$dbh->last_insert_id() not working

$dbh->last_insert_id() not working

am 16.06.2004 01:10:43 von Daniel Kasak

------------=_1087341213-29926-200
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi all.

I'm writing a helper object to synchronise data in DB server with fields
on a glade-generated form.
Part of that involves handling inserts:

eval {
$sth->execute (@bind_values) || die $dbh->errstr;
};

# If the above failed, there will be something in the special
variable $@
if ($@) {

# Dialog explaining error...
my $dialog = &msgbox(
$prospects->get_widget("Prospects"),
"Error updating recordset!",
"Database Server says:\n" . $dbh->errstr,
1
);
$dialog->run;
$dialog->destroy;
warn "Error updating recordset:\n$sql\n@bind_values\n" . $@ .
"\n\n";
return 0;

}

$pk = $dbh->last_insert_id();

When the above code runs, a record is inserted correctly - perfectly in
fact. The 'insert into' statement appears immediately in the MySQL query
log.
The problem is that the last line doesn't get a value - $pk is undef.

I haven't yet tried doing a 'select last_insert_id()' or 'select
@@identity' because I'm trying to keep the code as portable as possible
- so it can be used with other DB servers, and the obvious way of doing
this is by letting DBI take care of the details ( if it worked ).

Anyone know what's up?

Dan

--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: dkasak@nusconsulting.com.au
website: http://www.nusconsulting.com.au


------------=_1087341213-29926-200
Content-Type: text/plain; charset=us-ascii

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org
------------=_1087341213-29926-200--

Re: $dbh->last_insert_id() not working

am 16.06.2004 01:21:22 von mussatto

Daniel Kasak said:
> Hi all.
>
> I'm writing a helper object to synchronise data in DB server with fields
> on a glade-generated form.
> Part of that involves handling inserts:
>
> eval {
> $sth->execute (@bind_values) || die $dbh->errstr;
> };
>
> # If the above failed, there will be something in the special
> variable $@
> if ($@) {
>
> # Dialog explaining error...
> my $dialog = &msgbox(
> $prospects->get_widget("Prospects"),
> "Error updating recordset!",
> "Database Server says:\n" .
> $dbh->errstr, 1
> );
> $dialog->run;
> $dialog->destroy;
> warn "Error updating recordset:\n$sql\n@bind_values\n" . $@ .
> "\n\n";
> return 0;
>
> }
>
> $pk = $dbh->last_insert_id();
>
> When the above code runs, a record is inserted correctly - perfectly in
> fact. The 'insert into' statement appears immediately in the MySQL query
> log.
> The problem is that the last line doesn't get a value - $pk is undef.
>
> I haven't yet tried doing a 'select last_insert_id()' or 'select
> @@identity' because I'm trying to keep the code as portable as possible
> - so it can be used with other DB servers, and the obvious way of doing
> this is by letting DBI take care of the details ( if it worked ).
>
> Anyone know what's up?
>
> Dan
>
> --
> Daniel Kasak
> IT Developer
> NUS Consulting Group
> Level 5, 77 Pacific Highway
> North Sydney, NSW, Australia 2060
> T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
> email: dkasak@nusconsulting.com.au
> website: http://www.nusconsulting.com.au
syntax error: should be
$pk = $dbh->{'mysql_insertid'};

--
William R. Mussatto, Senior Systems Engineer
Ph. 909-920-9154 ext. 27
FAX. 909-608-7061



--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: $dbh->last_insert_id() not working

am 16.06.2004 01:21:22 von mussatto

Daniel Kasak said:
> Hi all.
>
> I'm writing a helper object to synchronise data in DB server with fields
> on a glade-generated form.
> Part of that involves handling inserts:
>
> eval {
> $sth->execute (@bind_values) || die $dbh->errstr;
> };
>
> # If the above failed, there will be something in the special
> variable $@
> if ($@) {
>
> # Dialog explaining error...
> my $dialog = &msgbox(
> $prospects->get_widget("Prospects"),
> "Error updating recordset!",
> "Database Server says:\n" .
> $dbh->errstr, 1
> );
> $dialog->run;
> $dialog->destroy;
> warn "Error updating recordset:\n$sql\n@bind_values\n" . $@ .
> "\n\n";
> return 0;
>
> }
>
> $pk = $dbh->last_insert_id();
>
> When the above code runs, a record is inserted correctly - perfectly in
> fact. The 'insert into' statement appears immediately in the MySQL query
> log.
> The problem is that the last line doesn't get a value - $pk is undef.
>
> I haven't yet tried doing a 'select last_insert_id()' or 'select
> @@identity' because I'm trying to keep the code as portable as possible
> - so it can be used with other DB servers, and the obvious way of doing
> this is by letting DBI take care of the details ( if it worked ).
>
> Anyone know what's up?
>
> Dan
>
> --
> Daniel Kasak
> IT Developer
> NUS Consulting Group
> Level 5, 77 Pacific Highway
> North Sydney, NSW, Australia 2060
> T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
> email: dkasak@nusconsulting.com.au
> website: http://www.nusconsulting.com.au
syntax error: should be
$pk = $dbh->{'mysql_insertid'};

--
William R. Mussatto, Senior Systems Engineer
Ph. 909-920-9154 ext. 27
FAX. 909-608-7061



--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: $dbh->last_insert_id() not working

am 16.06.2004 01:39:27 von Daniel Kasak

------------=_1087342936-23265-27
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

William R. Mussatto wrote:

>syntax error: should be
>$pk = $dbh->{'mysql_insertid'};
>
>
Thanks for the answer :)
Someone else in the main MySQL list said that to me, right before
suggesting I come here.

That's not what my DBI docs say though:

> $rv = $dbh->last_insert_id($catalog, $schema, $table, $field);

Any if I use the suggested:

> $pk = $dbh->{'mysql_insertid');

then I'm locking the object to work with MySQL only, and I'd really
prefer to use DBI's more portable 'last_insert_id()' function ... if the
damned thing works.

But thanks for the suggestion. I will use it for now to get things up &
running, and I might go bug the DBI developers if I can't get the above
working.

--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: dkasak@nusconsulting.com.au
website: http://www.nusconsulting.com.au


------------=_1087342936-23265-27
Content-Type: text/plain; charset=us-ascii

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org
------------=_1087342936-23265-27--

Re: $dbh->last_insert_id() not working

am 16.06.2004 01:39:27 von Daniel Kasak

------------=_1087342936-23265-27
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

William R. Mussatto wrote:

>syntax error: should be
>$pk = $dbh->{'mysql_insertid'};
>
>
Thanks for the answer :)
Someone else in the main MySQL list said that to me, right before
suggesting I come here.

That's not what my DBI docs say though:

> $rv = $dbh->last_insert_id($catalog, $schema, $table, $field);

Any if I use the suggested:

> $pk = $dbh->{'mysql_insertid');

then I'm locking the object to work with MySQL only, and I'd really
prefer to use DBI's more portable 'last_insert_id()' function ... if the
damned thing works.

But thanks for the suggestion. I will use it for now to get things up &
running, and I might go bug the DBI developers if I can't get the above
working.

--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: dkasak@nusconsulting.com.au
website: http://www.nusconsulting.com.au


------------=_1087342936-23265-27
Content-Type: text/plain; charset=us-ascii

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org
------------=_1087342936-23265-27--

Re: $dbh->last_insert_id() not working

am 16.06.2004 02:02:40 von mussatto

Daniel Kasak said:
> William R. Mussatto wrote:
>
>>syntax error: should be
>>$pk = $dbh->{'mysql_insertid'};
>>
>>
> Thanks for the answer :)
> Someone else in the main MySQL list said that to me, right before
> suggesting I come here.
>
> That's not what my DBI docs say though:
>
>> $rv = $dbh->last_insert_id($catalog, $schema, $table, $field);
>
> Any if I use the suggested:
>
>> $pk = $dbh->{'mysql_insertid');
>
> then I'm locking the object to work with MySQL only, and I'd really
> prefer to use DBI's more portable 'last_insert_id()' function ... if the
> damned thing works.
>
> But thanks for the suggestion. I will use it for now to get things up &
> running, and I might go bug the DBI developers if I can't get the above
> working.
>
> --
> Daniel Kasak
> IT Developer
> NUS Consulting Group
> Level 5, 77 Pacific Highway
> North Sydney, NSW, Australia 2060
> T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
> email: dkasak@nusconsulting.com.au
> website: http://www.nusconsulting.com.au
Put it, and any other mysql unique stuff into a .pm file and refer to
that. Then you will be able to change it only in one place. Just went
through convertsion MS SQL -> mysql and the date functions are NOT THE
SAME!!. Some databases don't even have an autoincrement function, so its
not part of the SQL standard.

--
William R. Mussatto, Senior Systems Engineer
Ph. 909-920-9154 ext. 27
FAX. 909-608-7061



--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: $dbh->last_insert_id() not working

am 16.06.2004 02:02:40 von mussatto

Daniel Kasak said:
> William R. Mussatto wrote:
>
>>syntax error: should be
>>$pk = $dbh->{'mysql_insertid'};
>>
>>
> Thanks for the answer :)
> Someone else in the main MySQL list said that to me, right before
> suggesting I come here.
>
> That's not what my DBI docs say though:
>
>> $rv = $dbh->last_insert_id($catalog, $schema, $table, $field);
>
> Any if I use the suggested:
>
>> $pk = $dbh->{'mysql_insertid');
>
> then I'm locking the object to work with MySQL only, and I'd really
> prefer to use DBI's more portable 'last_insert_id()' function ... if the
> damned thing works.
>
> But thanks for the suggestion. I will use it for now to get things up &
> running, and I might go bug the DBI developers if I can't get the above
> working.
>
> --
> Daniel Kasak
> IT Developer
> NUS Consulting Group
> Level 5, 77 Pacific Highway
> North Sydney, NSW, Australia 2060
> T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
> email: dkasak@nusconsulting.com.au
> website: http://www.nusconsulting.com.au
Put it, and any other mysql unique stuff into a .pm file and refer to
that. Then you will be able to change it only in one place. Just went
through convertsion MS SQL -> mysql and the date functions are NOT THE
SAME!!. Some databases don't even have an autoincrement function, so its
not part of the SQL standard.

--
William R. Mussatto, Senior Systems Engineer
Ph. 909-920-9154 ext. 27
FAX. 909-608-7061



--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: $dbh->last_insert_id() not working

am 16.06.2004 08:40:25 von Jochen Wiedmann

On Mi, 2004-06-16 at 01:39, Daniel Kasak wrote:

> Any if I use the suggested:
>
> > $pk = $dbh->{'mysql_insertid');
>
> then I'm locking the object to work with MySQL only, and I'd really
> prefer to use DBI's more portable 'last_insert_id()' function ... if the
> damned thing works.

Do you think that SELECT LAST_INSERT_ID() is different in that aspect?
:-)


Jochen


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: $dbh->last_insert_id() not working

am 16.06.2004 08:40:25 von Jochen Wiedmann

On Mi, 2004-06-16 at 01:39, Daniel Kasak wrote:

> Any if I use the suggested:
>
> > $pk = $dbh->{'mysql_insertid');
>
> then I'm locking the object to work with MySQL only, and I'd really
> prefer to use DBI's more portable 'last_insert_id()' function ... if the
> damned thing works.

Do you think that SELECT LAST_INSERT_ID() is different in that aspect?
:-)


Jochen


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: $dbh->last_insert_id() not working

am 17.06.2004 00:20:51 von Daniel Kasak

------------=_1087424619-28669-88
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Jochen Wiedmann wrote:

>On Mi, 2004-06-16 at 01:39, Daniel Kasak wrote:
>
>
>
>>Any if I use the suggested:
>>
>>
>>
>>>$pk = $dbh->{'mysql_insertid');
>>>
>>>
>>then I'm locking the object to work with MySQL only, and I'd really
>>prefer to use DBI's more portable 'last_insert_id()' function ... if the
>>damned thing works.
>>
>>
>
>Do you think that SELECT LAST_INSERT_ID() is different in that aspect?
>:-)
>
>
Huh?
DBI's database handle's last_insert_id() *function* is server neutral.
Have a look an the man page for DBI. The docs say specifically that it
works with MySQL, Postgres, Oracle, Informix, Sybase & SQL Server. So in
this way, I think the last_insert_id() function is quite different to both:

select LAST_INSERT_ID(), and
$dbh->{'mysql_insertid');

which both are MySQL-specific.

--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: dkasak@nusconsulting.com.au
website: http://www.nusconsulting.com.au


------------=_1087424619-28669-88
Content-Type: text/plain; charset=us-ascii

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org
------------=_1087424619-28669-88--

Re: $dbh->last_insert_id() not working

am 17.06.2004 00:20:51 von Daniel Kasak

------------=_1087424619-28669-88
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Jochen Wiedmann wrote:

>On Mi, 2004-06-16 at 01:39, Daniel Kasak wrote:
>
>
>
>>Any if I use the suggested:
>>
>>
>>
>>>$pk = $dbh->{'mysql_insertid');
>>>
>>>
>>then I'm locking the object to work with MySQL only, and I'd really
>>prefer to use DBI's more portable 'last_insert_id()' function ... if the
>>damned thing works.
>>
>>
>
>Do you think that SELECT LAST_INSERT_ID() is different in that aspect?
>:-)
>
>
Huh?
DBI's database handle's last_insert_id() *function* is server neutral.
Have a look an the man page for DBI. The docs say specifically that it
works with MySQL, Postgres, Oracle, Informix, Sybase & SQL Server. So in
this way, I think the last_insert_id() function is quite different to both:

select LAST_INSERT_ID(), and
$dbh->{'mysql_insertid');

which both are MySQL-specific.

--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: dkasak@nusconsulting.com.au
website: http://www.nusconsulting.com.au


------------=_1087424619-28669-88
Content-Type: text/plain; charset=us-ascii

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org
------------=_1087424619-28669-88--

encrypt tables

am 17.06.2004 16:44:32 von lshen

Dose anyone know the command to do the encryption the table? thanks

Brian
----- Original Message -----
From: "Daniel Kasak"
To: "Jochen Wiedmann" ; "William R. Mussatto"
;
Sent: Wednesday, June 16, 2004 6:20 PM
Subject: Re: $dbh->last_insert_id() not working


> Jochen Wiedmann wrote:
>
> >On Mi, 2004-06-16 at 01:39, Daniel Kasak wrote:
> >
> >
> >
> >>Any if I use the suggested:
> >>
> >>
> >>
> >>>$pk = $dbh->{'mysql_insertid');
> >>>
> >>>
> >>then I'm locking the object to work with MySQL only, and I'd really
> >>prefer to use DBI's more portable 'last_insert_id()' function ... if the
> >>damned thing works.
> >>
> >>
> >
> >Do you think that SELECT LAST_INSERT_ID() is different in that aspect?
> >:-)
> >
> >
> Huh?
> DBI's database handle's last_insert_id() *function* is server neutral.
> Have a look an the man page for DBI. The docs say specifically that it
> works with MySQL, Postgres, Oracle, Informix, Sybase & SQL Server. So in
> this way, I think the last_insert_id() function is quite different to
both:
>
> select LAST_INSERT_ID(), and
> $dbh->{'mysql_insertid');
>
> which both are MySQL-specific.
>
> --
> Daniel Kasak
> IT Developer
> NUS Consulting Group
> Level 5, 77 Pacific Highway
> North Sydney, NSW, Australia 2060
> T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
> email: dkasak@nusconsulting.com.au
> website: http://www.nusconsulting.com.au
>
>


------------------------------------------------------------ ----------------
----


> --
> MySQL Perl Mailing List
> For list archives: http://lists.mysql.com/perl
> To unsubscribe:
http://lists.mysql.com/perl?unsub=lshen@pop900.gsfc.nasa.gov


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

encrypt tables

am 17.06.2004 16:44:32 von lshen

Dose anyone know the command to do the encryption the table? thanks

Brian
----- Original Message -----
From: "Daniel Kasak"
To: "Jochen Wiedmann" ; "William R. Mussatto"
;
Sent: Wednesday, June 16, 2004 6:20 PM
Subject: Re: $dbh->last_insert_id() not working


> Jochen Wiedmann wrote:
>
> >On Mi, 2004-06-16 at 01:39, Daniel Kasak wrote:
> >
> >
> >
> >>Any if I use the suggested:
> >>
> >>
> >>
> >>>$pk = $dbh->{'mysql_insertid');
> >>>
> >>>
> >>then I'm locking the object to work with MySQL only, and I'd really
> >>prefer to use DBI's more portable 'last_insert_id()' function ... if the
> >>damned thing works.
> >>
> >>
> >
> >Do you think that SELECT LAST_INSERT_ID() is different in that aspect?
> >:-)
> >
> >
> Huh?
> DBI's database handle's last_insert_id() *function* is server neutral.
> Have a look an the man page for DBI. The docs say specifically that it
> works with MySQL, Postgres, Oracle, Informix, Sybase & SQL Server. So in
> this way, I think the last_insert_id() function is quite different to
both:
>
> select LAST_INSERT_ID(), and
> $dbh->{'mysql_insertid');
>
> which both are MySQL-specific.
>
> --
> Daniel Kasak
> IT Developer
> NUS Consulting Group
> Level 5, 77 Pacific Highway
> North Sydney, NSW, Australia 2060
> T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
> email: dkasak@nusconsulting.com.au
> website: http://www.nusconsulting.com.au
>
>


------------------------------------------------------------ ----------------
----


> --
> MySQL Perl Mailing List
> For list archives: http://lists.mysql.com/perl
> To unsubscribe:
http://lists.mysql.com/perl?unsub=lshen@pop900.gsfc.nasa.gov


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org