SQLite Insert ID - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: SQLite Insert ID (
/showthread.php?tid=617904)
SQLite Insert ID -
DTV - 28.09.2016
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?
Re: SQLite Insert ID -
JaKe Elite - 28.09.2016
Is this what you are looking for?
A snippet that I copied from JakAdmin 3.4.1
PHP Code:
new
query[128 * 3]
;
format(query, sizeof(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(Database, query);
new DBResult: result;
result = db_query(Database, "SELECT last_insert_rowid()");
User[playerid][accountID] = db_get_field_int(result);
db_free_result(result);
Re: SQLite Insert ID -
SyS - 28.09.2016
Quote:
Originally Posted by JaKe Elite
Is this what you are looking for?
A snippet that I copied from JakAdmin 3.4.1
PHP Code:
new
query[128 * 3]
;
format(query, sizeof(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(Database, query);
new DBResult: result;
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
Re: SQLite Insert ID -
DTV - 29.09.2016
I decided that I'm going to use the MySQL plugin, but thanks for the help anyways.