AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   SQL: Very confused! (https://forums.alliedmods.net/showthread.php?t=66788)

KaOs 02-08-2008 18:18

SQL: Very confused!
 
Ok lol this is my last question..

Now, I'm not an idiot, I program PHP and MySQL all day long, but this I just don't understand..

Code:

                new plrUniqueID;
                new Handle:Result = SQL_Query(DB, QueryString);
                plrUniqueID = SQL_GetInsertId(Result);

I get error:
Quote:

Native "SQL_GetInsertId" reported: Invalid statement or db Handle 5f9f0120 (error: 2)




Then I tried:

Code:

                new plrUniqueID;
                new Handle:Result = SQL_Query(DB, QueryString);
                SQL_FetchRow(Result);
                plrUniqueID = SQL_GetInsertId(Result);

I get error:
Quote:

Native "SQL_FetchRow" reported: No current result set

WITH BOTH CODES I GET THE ROW INSERTED INTO MY DB! The query is executing!!!

Nican 02-08-2008 18:21

Re: SQL: Very confused!
 
Try using
PHP Code:

plrUniqueID SQL_GetInsertId(DB); 

If that does not work, take a look at:
http://dev.mysql.com/doc/refman/5.0/...last-insert-id

KaOs 02-08-2008 18:52

Re: SQL: Very confused!
 
Quote:

Originally Posted by Nican (Post 583071)
Try using
PHP Code:

plrUniqueID SQL_GetInsertId(DB); 

If that does not work, take a look at:
http://dev.mysql.com/doc/refman/5.0/...last-insert-id

Nothing works. I just selected ONE row ordering by insert time desc, that worked.

Nican 02-08-2008 20:37

Re: SQL: Very confused!
 
Quick question:

Were you using SQLite or MySQL?

KaOs 02-09-2008 00:24

Re: SQL: Very confused!
 
Quote:

Originally Posted by Nican (Post 583111)
Quick question:

Were you using SQLite or MySQL?

MySQL.

KMFrog 02-09-2008 08:21

Re: SQL: Very confused!
 
have you connected to the db before you are starting to query?

Scuzzy 02-09-2008 12:23

Re: SQL: Very confused!
 
Let's see everything from where you connect to the db...

Scuzzy

KaOs 02-09-2008 13:35

Re: SQL: Very confused!
 
It's ok guys I found a work around. It appears as though something is wrong with that function..

generalmemer 07-28-2020 11:25

Re: SQL: Very confused!
 
Just bumped here and since he didn't mind to let us all know his solution 12 years ago, it's that you have to call SQL_GetInsertId() in the query callback using the main database connection handle and take it from there. Because the query doesn't execute instantly, we have to wait for the callback. Otherwise it'll return 0. Nothing is wrong with the function.

asherkin 07-28-2020 11:27

Re: SQL: Very confused!
 
Quote:

Originally Posted by generalmemer (Post 2712033)
Just bumped here and since he didn't mind to let us all know his solution 12 years ago, it's that you have to call SQL_GetInsertId() in the query callback using the main database connection handle and take it from there. Because the query doesn't execute instantly, we have to wait for the callback. Otherwise it'll return 0. Nothing is wrong with the function.

This 12 year old thread far predates threaded SQL support - there was no callback involved in the original code.


All times are GMT -4. The time now is 00:47.

Powered by vBulletin®
Copyright ©2000 - 2020, vBulletin Solutions, Inc.