diff options
-rw-r--r-- | Changelog-Trunk.txt | 3 | ||||
-rw-r--r-- | doc/script_commands.txt | 6 | ||||
-rw-r--r-- | src/map/script.c | 43 |
3 files changed, 40 insertions, 12 deletions
diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt index 4c50c4cb3..9b3265058 100644 --- a/Changelog-Trunk.txt +++ b/Changelog-Trunk.txt @@ -3,6 +3,9 @@ Date Added AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK. IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK. +2007/12/11 + * Added query_logsql script command to perform sql commands using the log + db connection. 2007/12/10 * Cleaned up clif_setdisguise and fixed it for PACKETVER>=9. * Added missing range/skill-mask info to reflected damage (fixes autospells diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 40c8e9224..285148a14 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -92,6 +92,8 @@ //= Added script function 'strnpcinfo' [ultramage] //= 3.10.20071122 //= Added setnpcdisplay. [FlavioJS] +//= 3.10.20071211 +//= Added query_logsql. [Skotlex] //===== Description ======================================= //= A reference manual for the eAthena scripting language, //= sorted out depending on their functionality. @@ -5953,6 +5955,7 @@ set @i, distance(100,200,101,202); --------------------------------------- *query_sql "your MySQL query", <array variable> {,<array variable>, ...}; +*query_logsql "your MySQL query", <array variable> {,<array variable>, ...}; Puts up to 128 rows of values into the arrays and returns the number of rows. @@ -5967,6 +5970,9 @@ mes "5."+@name$[4]+"("+@fame[4]+")"; Note: In the TXT version it doesn't fill the array and always return -1. Note: Use $ as suffix in the array to receive all data as text. +Note: The difference between query_sql and query_logsql is that the latter +uses the sql connection to the log database, and should be used when you want +to query the server log tables. --------------------------------------- diff --git a/src/map/script.c b/src/map/script.c index 63d3f1a16..534802d82 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -11651,9 +11651,9 @@ BUILDIN_FUNC(setd) return 0; } -BUILDIN_FUNC(query_sql) -{ #ifndef TXT_ONLY +int buildin_query_sql_sub(struct script_state* st, Sql* handle) +{ int i, j; TBL_PC* sd = NULL; const char* query; @@ -11695,22 +11695,22 @@ BUILDIN_FUNC(query_sql) // Execute the query query = script_getstr(st,2); - if( SQL_ERROR == Sql_QueryStr(mmysql_handle, query) ) + if( SQL_ERROR == Sql_QueryStr(handle, query) ) { - Sql_ShowDebug(mmysql_handle); + Sql_ShowDebug(handle); script_pushint(st, 0); return 1; } - if( Sql_NumRows(mmysql_handle) == 0 ) + if( Sql_NumRows(handle) == 0 ) {// No data received - Sql_FreeResult(mmysql_handle); + Sql_FreeResult(handle); script_pushint(st, 0); return 0; } // Count the number of columns to store - num_cols = Sql_NumColumns(mmysql_handle); + num_cols = Sql_NumColumns(handle); if( num_vars < num_cols ) { ShowWarning("script:query_sql: Too many columns, discarding last %u columns.\n", (unsigned int)(num_cols-num_vars)); @@ -11723,14 +11723,14 @@ BUILDIN_FUNC(query_sql) } // Store data - for( i = 0; i < max_rows && SQL_SUCCESS == Sql_NextRow(mmysql_handle); ++i ) + for( i = 0; i < max_rows && SQL_SUCCESS == Sql_NextRow(handle); ++i ) { for( j = 0; j < num_vars; ++j ) { char* str = NULL; if( j < num_cols ) - Sql_GetData(mmysql_handle, j, &str, NULL); + Sql_GetData(handle, j, &str, NULL); data = script_getdata(st, j+3); name = reference_getname(data); @@ -11740,21 +11740,39 @@ BUILDIN_FUNC(query_sql) setd_sub(st, sd, name, i, (void *)(str?atoi(str):0), reference_getref(data)); } } - if( i == max_rows && max_rows < Sql_NumRows(mmysql_handle) ) + if( i == max_rows && max_rows < Sql_NumRows(handle) ) { - ShowWarning("script:query_sql: Only %d/%u rows have been stored.\n", max_rows, (unsigned int)Sql_NumRows(mmysql_handle)); + ShowWarning("script:query_sql: Only %d/%u rows have been stored.\n", max_rows, (unsigned int)Sql_NumRows(handle)); script_reportsrc(st); } // Free data - Sql_FreeResult(mmysql_handle); + Sql_FreeResult(handle); script_pushint(st, i); + return 0; +} +#endif + +BUILDIN_FUNC(query_sql) +{ +#ifndef TXT_ONLY + return buildin_query_sql_sub(st, mmysql_handle); #else //for TXT version, we always return -1 script_pushint(st,-1); + return 0; #endif +} +BUILDIN_FUNC(query_logsql) +{ +#ifndef TXT_ONLY + return buildin_query_sql_sub(st, logmysql_handle); +#else + //for TXT version, we always return -1 + script_pushint(st,-1); return 0; +#endif } //Allows escaping of a given string. @@ -13226,6 +13244,7 @@ struct script_function buildin_func[] = { BUILDIN_DEF(getmonsterinfo,"ii"), //Lupus BUILDIN_DEF(axtoi,"s"), BUILDIN_DEF(query_sql,"s*"), + BUILDIN_DEF(query_logsql,"s*"), BUILDIN_DEF(escape_sql,"s"), BUILDIN_DEF(atoi,"s"), // [zBuffer] List of player cont commands ---> |