Skip Menu |

This queue is for tickets about the Fey CPAN distribution.

Report information
The Basics
Id: 63881
Status: open
Priority: 0/
Queue: Fey

People
Owner: Nobody in particular
Requestors: jldasch [...] mac.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Order of values in insert incorrect
Date: Mon, 13 Dec 2010 10:45:14 -0700
To: bug-fey [...] rt.cpan.org
From: John Daschbach <jldasch [...] mac.com>
The following appears to be a bug. my $ins = Fey::SQL->new_insert(); my ($datecnttable, $sdate, $dcnt) = $dbUtil->getTableAndColumns('datecount',['sdate', 'dcnt']); $ins->into($datecnttable); $ins->values( sdate => $ph, $dcnt->name() => $ph); my $sth2 = $dbUtil->prepareSth( $ins, 1 ); ================== Printing the sql via $sql->sql( $dbh ) ================= INSERT INTO "datecount" ("dcnt", "sdate") VALUES (?, ?) Somehow Fey is reversing the order of the values passed in the values() call when constructing the SQL. Also, although not a bug, it seems odd that a few->insert->values() method will not take a column object, but requires an explicit name call. It would seem more consistent with a Fey select if one could pass a column object to the values() method. -John
Subject: Re: [rt.cpan.org #63881] Order of values in insert incorrect
Date: Mon, 13 Dec 2010 11:49:05 -0600 (CST)
To: John Daschbach via RT <bug-Fey [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
On Mon, 13 Dec 2010, John Daschbach via RT wrote: Show quoted text
> The following appears to be a bug. > > my $ins = Fey::SQL->new_insert(); > my ($datecnttable, $sdate, $dcnt) > = $dbUtil->getTableAndColumns('datecount',['sdate', 'dcnt']); > $ins->into($datecnttable); > $ins->values( sdate => $ph, $dcnt->name() => $ph); > my $sth2 = $dbUtil->prepareSth( $ins, 1 ); > > ================== > Printing the sql via $sql->sql( $dbh ) > ================= > > INSERT INTO "datecount" ("dcnt", "sdate") VALUES (?, ?) > > Somehow Fey is reversing the order of the values passed in the values() call when constructing the SQL.
How is this a bug? The column order in a SQL insert shouldn't matter, should it? Show quoted text
> Also, although not a bug, it seems odd that a few->insert->values() > method will not take a column object, but requires an explicit name > call. It would seem more consistent with a Fey select if one could pass > a column object to the values() method.
Please file a separate ticket for this. Thanks, -dave /*============================================================ http://VegGuide.org http://blog.urth.org Your guide to all that's veg House Absolute(ly Pointless) ============================================================*/
Subject: Re: [rt.cpan.org #63881] Order of values in insert incorrect
Date: Mon, 13 Dec 2010 12:27:10 -0700
To: bug-Fey [...] rt.cpan.org
From: John Daschbach <jldasch [...] mac.com>
The order matters because when you call ->execute( v1, v2, ...) it's a call by position. You can order the values() clause any way you want, but when you call execute() you call with the values ordered as they are in how you constructed the values() clause. When I construct a values() clause with Fey, and print the resulting SQL, the resulting SQL has the column names in the same order, independent of how I ordered them in the values() call. Without knowing the order of the values() produced by Fey I can't call execute() with the parameters in the correct positions. The Fey insert() constructor works fine if you call it with literal values, but if you call with a Fey::Placeholder because you want to repeatedly call DBI execute() it's a problem. If you are doing a million inserts you need the efficiency of the standard DBI prepare() and execute() approach. The Fey select() operates position wise, which is needed when you retrieve data using something like a fetchall_arrayref(). The insert requires some work around if you want to use DBI execute() on the resulting statement handle. -John On Dec 13, 2010, at 10:49 AM, autarch@urth.org via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=63881 > > > On Mon, 13 Dec 2010, John Daschbach via RT wrote: >
>> The following appears to be a bug. >> >> my $ins = Fey::SQL->new_insert(); >> my ($datecnttable, $sdate, $dcnt) >> = $dbUtil->getTableAndColumns('datecount',['sdate', 'dcnt']); >> $ins->into($datecnttable); >> $ins->values( sdate => $ph, $dcnt->name() => $ph); >> my $sth2 = $dbUtil->prepareSth( $ins, 1 ); >> >> ================== >> Printing the sql via $sql->sql( $dbh ) >> ================= >> >> INSERT INTO "datecount" ("dcnt", "sdate") VALUES (?, ?) >> >> Somehow Fey is reversing the order of the values passed in the values() call when constructing the SQL.
> > How is this a bug? The column order in a SQL insert shouldn't matter, > should it? >
>> Also, although not a bug, it seems odd that a few->insert->values() >> method will not take a column object, but requires an explicit name >> call. It would seem more consistent with a Fey select if one could pass >> a column object to the values() method.
> > Please file a separate ticket for this. > > > Thanks, > > -dave > > /*============================================================ > http://VegGuide.org http://blog.urth.org > Your guide to all that's veg House Absolute(ly Pointless) > ============================================================*/ >
Subject: $table->columns (and $schema->tables, etc) does not guarantee any particular order in the returned object
Yes, you're right that column order is important. I'm not sure what I was thinking. However, looking more closely I realize that order is preserved. If you want a specific column order in the INTO clause you need to pass the columns in that order. If you simply pass a table object then internally the code calls $table->columns. The order of columns() is currently random, which is the real bug.
Subject: Re: [rt.cpan.org #63881] $table->columns (and $schema->tables, etc) does not guarantee any particular order in the returned object
Date: Tue, 14 Dec 2010 16:06:06 -0700
To: bug-Fey [...] rt.cpan.org
From: John Daschbach <jldasch [...] mac.com>
Thanks. I was going by the one example in the documentation my $sql = Fey::SQL->new_insert(); # INSERT INTO Part # (part_id, name, quantity) # VALUES # (?, ?, ?) $sql->insert()->into($Part); my $ph = Fey::Placeholder->new(); $sql->values( part_id => $ph, name => $ph, quantity => $ph, ); print $sql->sql($dbh); where I assume $Part is a table object. The example sql is how I think about it, and I assumed that the Fey values() method combined the column list (part_id, name, quantity) with the values (?,?,?) clause. So if the example in the documentation were changed to use column objects in the into() method I would have gotten it wrong. But then the syntax seems redundant to use column names in the into() method and again in the values() method. If using the column objects in the into clause one might be able to just pass $ph in the values clause OR automatically generate the values clause with placeholders. In other words $sql->insert()->into($part_id, $name, $quantity) would generate the sql INSERT INTO Part (part_id, name, quantity) VALUES (?,?,?) If one called $sql->values(val1, val2, val3) it would instead generate INSERT INTO Part (part_id, name, quantity) VALUES (val1, val2, val3) Except that it's generally good practice to use the DBI placeholders and call execute() with the bind parameters so quoting or escaping is correct. Thanks for the clarification. -John On Dec 14, 2010, at 3:01 PM, Dave Rolsky via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=63881 > > > Yes, you're right that column order is important. I'm not sure what I > was thinking. > > However, looking more closely I realize that order is preserved. If you > want a specific column order in the INTO clause you need to pass the > columns in that order. If you simply pass a table object then internally > the code calls $table->columns. The order of columns() is currently > random, which is the real bug.