Forráskód Böngészése

- Added query_logsql script command to perform sql commands using the log db connection.

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@11892 54d463be-8e91-2dee-dedb-b68131a5f0ec
skotlex 17 éve
szülő
commit
9d353fba9b
3 módosított fájl, 40 hozzáadás és 12 törlés
  1. 3 0
      Changelog-Trunk.txt
  2. 6 0
      doc/script_commands.txt
  3. 31 12
      src/map/script.c

+ 3 - 0
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

+ 6 - 0
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.
 
 ---------------------------------------
 

+ 31 - 12
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 --->