[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


Messages In This Thread
db_query error reporting - by Slice - 07.10.2013, 12:19
Re: db_query error reporting - by QuaTTrO - 07.10.2013, 12:23
Re: db_query error reporting - by kristo - 07.10.2013, 12:32
Re: db_query error reporting - by Slice - 07.10.2013, 12:35
Re: db_query error reporting - by Niko_boy - 09.10.2013, 07:07
Re: db_query error reporting - by Konstantinos - 09.10.2013, 09:18
Re: db_query error reporting - by Patrick - 11.05.2014, 19:03

Forum Jump:


Users browsing this thread: 2 Guest(s)