[Include] db_query error reporting
#1

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
Reply
#2

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!
Reply
#3

crashdetect.inc? Did I miss something?
Reply
#4

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
Reply
#5

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!
Reply
#6

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
Reply
#7

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)