Raised This Month: $12 Target: $400
 3% 

SQL: Very confused!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KaOs
Senior Member
Join Date: Apr 2004
Old 02-08-2008 , 18:18   SQL: Very confused!
Reply With Quote #1

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!!!
__________________
KaOs is offline
Send a message via AIM to KaOs Send a message via MSN to KaOs
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 02-08-2008 , 18:21   Re: SQL: Very confused!
Reply With Quote #2

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
__________________
http://www.nican132.com
I require reputation!

Last edited by Nican; 02-08-2008 at 18:29.
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
KaOs
Senior Member
Join Date: Apr 2004
Old 02-08-2008 , 18:52   Re: SQL: Very confused!
Reply With Quote #3

Quote:
Originally Posted by Nican View Post
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.
__________________
KaOs is offline
Send a message via AIM to KaOs Send a message via MSN to KaOs
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 02-08-2008 , 20:37   Re: SQL: Very confused!
Reply With Quote #4

Quick question:

Were you using SQLite or MySQL?
__________________
http://www.nican132.com
I require reputation!
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
KaOs
Senior Member
Join Date: Apr 2004
Old 02-09-2008 , 00:24   Re: SQL: Very confused!
Reply With Quote #5

Quote:
Originally Posted by Nican View Post
Quick question:

Were you using SQLite or MySQL?
MySQL.
__________________
KaOs is offline
Send a message via AIM to KaOs Send a message via MSN to KaOs
KMFrog
Senior Member
Join Date: Oct 2007
Old 02-09-2008 , 08:21   Re: SQL: Very confused!
Reply With Quote #6

have you connected to the db before you are starting to query?
__________________
Was I helpful or not? Rate Me!
KMFrog is offline
Scuzzy
Senior Member
Join Date: Oct 2007
Old 02-09-2008 , 12:23   Re: SQL: Very confused!
Reply With Quote #7

Let's see everything from where you connect to the db...

Scuzzy
Scuzzy is offline
KaOs
Senior Member
Join Date: Apr 2004
Old 02-09-2008 , 13:35   Re: SQL: Very confused!
Reply With Quote #8

It's ok guys I found a work around. It appears as though something is wrong with that function..
__________________
KaOs is offline
Send a message via AIM to KaOs Send a message via MSN to KaOs
generalmemer
Member
Join Date: Sep 2017
Old 07-28-2020 , 11:25   Re: SQL: Very confused!
Reply With Quote #9

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.
generalmemer is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 07-28-2020 , 11:27   Re: SQL: Very confused!
Reply With Quote #10

Quote:
Originally Posted by generalmemer View Post
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.
__________________
asherkin is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:59.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode