[Include] IDB - Remove boilerplate code when using SQLite
#1

IDB

I created this in an attempt to remove excess code around SQL queries. I come from languages where you can pass anonymous functions, which are damn useful. I've tried to emulate it in PAWN.

The code is on github, or you can view it directly.

Readme is on github.

Quick example, loop through all results of a query:

PHP код:
idb_all(values[2][MAX_PLAYER_NAME], "SELECT `name`, `points` FROM `users` WHERE `points` > 100;") {
    
printf("%s has %s points"values[0], values[1]);

Comments & pull requests welcome
Reply
#2

great!!
Reply
#3

Looks good but I don't find it appealing for optimization.

I prefer writing a couple of more lines than to use this because of the following:
PHP код:
idb_all(values[3][128], "SELECT `string`, `integer`, `float` FROM `table`")
{
    
// 128 cells for a string (that needs 128 cells), not wasted
    // 128 cells for an integer, wasted
    // 128 cells for a float, wasted
    // 128 * 2 = 256 cells wasted
}
new 
DBResultresult db_query(database"SELECT `string`, `integer`, `float` FROM `table`");
if (
db_num_rows(result))
{
    new 
str[128], ivalFloatfval;
    
db_get_field(result0str128);
    
ival db_get_field_int(result1);
    
fval db_get_field_float(result2);
    
// Nothing is wasted
}
db_free_result(result); 
Plus, adding to that, you could also reuse arrays.
PHP код:
new
    
str[128],
    
DBResultresult db_query(database"SELECT `string`, `integer`, `float` FROM `table`");
if (
db_num_rows(result))
{
    new 
ivalFloatfval;
    
db_get_field(result0str128);
    
ival db_get_field_int(result1);
    
fval db_get_field_float(result2);
    
// Nothing is wasted
}
db_free_result(result);
format(strsizeof (str), "String reused ...", ...); 
Reply
#4

Yeah I agree, if you want efficiency you should use the natives directly
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)