SA-MP Forums Archive
[Include] db_query error reporting - 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: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] db_query error reporting (/showthread.php?tid=468260)



db_query error reporting - Slice - 07.10.2013

Note: If you're using SQLite Improved, update to the latest version instead of using this include.

This is an include that makes db_query report errors when the server is running on Windows. It patches the db_query function to make this possible (I made sure it's ok to publish this).

Usage
You need amx_assembly. When you've downloaded it, simply put this before you use db_query:
pawn Код:
#include <db-errors>
Advanced usage
pawn Код:
public OnSQLiteQueryError(error[]) {
    printf("db_query error: %s", error);
    // if you have crashdetect (and crashdetect.inc), you can see where the error happened:
    PrintAmxBacktrace();
}
Warning
If you have filterscripts that use db_query, be sure to include this file in them, too.

Compatibility
This works only on Windows, on Linux it will simply not report errors. I've tested this on a few old SA-MP versions and it works on them, too. Unless the db_* functions are modified, it should work in future versions.

Example
pawn Код:
public OnFilterScriptInit() {
    new DB:db = db_open("test.db");
   
    // no such table: some_table
    db_query(db, "SELECT * FROM some_table;");
    // No error (or "table test already exists")
    db_query(db, "CREATE TABLE test (a, b, c)");
    // no such column name: name
    db_query(db, "SELECT name FROM test");
    // near "bla": syntax error
    db_query(db, "SELECT test FRMO bla");
   
    db_close(db);
}
Credits
Lots of credits goes to Zeex for making this all possible with amx_assembly.

Download
https://gist.github.com/oscar-broman/6866913


Re: db_query error reporting - QuaTTrO - 07.10.2013

Finally! This is the most useful SQL include ever. Finally i will able to see what is wrong in my query and fix it faster!

Good work!


Re: db_query error reporting - kristo - 07.10.2013

crashdetect.inc? Did I miss something?


Re: db_query error reporting - Slice - 07.10.2013

Quote:
Originally Posted by kvann
Посмотреть сообщение
crashdetect.inc? Did I miss something?
It was recently added to crashdetect.

https://github.com/Zeex/samp-plugin-...rashdetect.inc


Re: db_query error reporting - Niko_boy - 09.10.2013

usefull include and at same time it displayed about a include that i didnt knew about o.O crashdetect ;o

anyways i been using SQLlite since long and would implement new version , thanks for it!


Re: db_query error reporting - Konstantinos - 09.10.2013

Great job! That was a disadvantage of SQLite when the only possible way to detect the errors from a query was to execute it on a SQLite Browser.

@For those who use crashdetect, check the latest posts because the first post is never updated (another account).

4.12 is available: https://github.com/Zeex/samp-plugin-...ases/tag/v4.12


Re: db_query error reporting - Patrick - 11.05.2014

If anyone is still using this, I found a little typo in the include, really simple fix for this db-errors if you are using OnSQLiteQueryError for in-depth look of the error/warning.

Problem: warning 235: public function lacks forward declaration (symbol "THE_OnSQLiteQueryError")

Fix: https://gist.github.com/pds2k12/f3ed17bd6147730be3b8