sqlite last_insert_id() -
Baltazar - 09.04.2014
How do I get row-id of a just-inserted row on SQLite?
Re: db_query() miltiple statements -
Niko_boy - 09.04.2014
i am not quite sure about this but i too needed something like that in past. try this:
SELECT last_insert_rowid();
EDIT: ^ ignore that it didnt worked for me.
i think you will have to play with queries to do so e.g: add new field and set its value to something and reset all others when new query executed etc..
Re: db_query() miltiple statements -
Baltazar - 09.04.2014
I mean here's the statement:
Код:
qresult = db_query(sqlite, "SELECT LAST_INSERT_ID()");
qresult holds ZERO this way. What else can I try to get just-inserted row id?
Re: db_query() miltiple statements -
IstuntmanI - 09.04.2014
cache_insert_id after a query (mysql_(p/t)query, doesn't matter), if you want to use it in a INSERT query.
https://sampwiki.blast.hk/wiki/MySQL/R33#cache_insert_id
Re: db_query() miltiple statements -
Baltazar - 09.04.2014
Quote:
Originally Posted by IstuntmanI
|
We are talking about SQLite (its implementation into SA:MP) actually... not about MySQL
Re: db_query() miltiple statements -
Niko_boy - 09.04.2014
Well i think this is not the best idea or maybe very bad idea lol, but this is what i can suggest is:
Add a column named Just_insert to your table. Perform both queries together:
pawn Код:
UPDATE `tableName` SET Just_insert = 0;
INSERT INTO `tableName` (fieldName1,...fieldNameN,Just_insert) VALUES('value1',..'valueN',1)
Note that '1' in end it is to set value of current inserting row to 1 and the above query reset all other valeus to 0.
There can be INSERT query or UPDATE too. Depends since you are asking for latest "Inserted"
laters you can do is:
pawn Код:
SELECT `rowid` from `tableName` WHERE `Just_insert`=1;
it must be handled with care for best results
Re: db_query() miltiple statements -
IstuntmanI - 09.04.2014
Quote:
Originally Posted by Baltazar
We are talking about SQLite (its implementation into SA:MP) actually... not about MySQL
|
My mistake, sorry. Umm... you could also use MySQL, it is pretty much the same thing, and it is better.
Re: db_query() miltiple statements -
Niko_boy - 09.04.2014
Quote:
Originally Posted by IstuntmanI
My mistake, sorry. Umm... you could also use MySQL, it is pretty much the same thing, and it is better. 
|
erm no. it depend on usage which makes it better or no, dotn want any discussion for MySQL vs SQLite . Since SQLite does all good basicly and no bad than MySQL.
Anyway @OP see my post maybe that might be usefull
Re: db_query() miltiple statements -
Pottus - 09.04.2014
There is a feature in sqlitei to do this.
https://sampforum.blast.hk/showthread.php?tid=303682
db_last_insert_rowid(DB:db)
HOWEVER I tried using this once and it was crashing my server I'll ask Slice if he can fix this issue.
You could also try using db_insert() in SQLitei it will return the row id.
pawn Код:
stock db_insert(DB:db, const szQuery[]) {
new
DBResult:dbrResult = db_query(db, szQuery, false)
;
if (dbrResult) {
db_free_result(dbrResult);
return db_last_insert_rowid(db);
}
return 0;
}
Re: db_query() miltiple statements -
Niko_boy - 09.04.2014
Quote:
Originally Posted by [uL]Pottus
|
didnt knew about that
btw can anyone give thoughts about my method? It SEEM TO BE a very bad method. I just want to know though cuz i was thinking to use like that in past.. but anyway if SQLitei does it good , i will use that.