SQLite Insert ID
#1

I'm learning the functions of SQLite and was wondering if there's a function that works the same as cache_insert_id. If not, how would I script the same kind of function for SQLite?
Reply
#2

Is this what you are looking for?

A snippet that I copied from JakAdmin 3.4.1

PHP Code:
new
    
query[128 3]
;

format(querysizeof(query),
    
"INSERT INTO `users` (`username`, `IP`, `joindate`, `password`) VALUES ('%s', '%s', '%s', '%s')",\
        
DB_Escape(pName(playerid)),
        
DB_Escape(User[playerid][accountIP]),
        
DB_Escape(User[playerid][accountDate]),
        
DB_Escape(password),
        
User[playerid][accountScore],
        
User[playerid][accountCash],
        
DB_Escape(User[playerid][accountQuestion]),
        
DB_Escape(User[playerid][accountAnswer])
);
db_query(Databasequery);

new 
DBResultresult;
result db_query(Database"SELECT last_insert_rowid()");
User[playerid][accountID] = db_get_field_int(result);
db_free_result(result); 
Reply
#3

Quote:
Originally Posted by JaKe Elite
View Post
Is this what you are looking for?

A snippet that I copied from JakAdmin 3.4.1

PHP Code:
new
    
query[128 3]
;
format(querysizeof(query),
    
"INSERT INTO `users` (`username`, `IP`, `joindate`, `password`) VALUES ('%s', '%s', '%s', '%s')",\
        
DB_Escape(pName(playerid)),
        
DB_Escape(User[playerid][accountIP]),
        
DB_Escape(User[playerid][accountDate]),
        
DB_Escape(password),
        
User[playerid][accountScore],
        
User[playerid][accountCash],
        
DB_Escape(User[playerid][accountQuestion]),
        
DB_Escape(User[playerid][accountAnswer])
);
db_query(Databasequery);
new 
DBResultresult;
result db_query(Database"SELECT last_insert_rowid()");
User[playerid][accountID] = db_get_field_int(result);
db_free_result(result); 
since new version you can use ℅q specifier instead of db escape
Reply
#4

I decided that I'm going to use the MySQL plugin, but thanks for the help anyways.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)