# HG changeset patch # User nrich@ii.net # Date 1251810902 0 # Node ID 03ed0ca098373316ec7034219aa461b43f5253f3 # Parent 999ef93f0dbc0e572ab33fc79aadf74b144ece48 Add __tostring method to connection and statement objects. diff -r 999ef93f0dbc -r 03ed0ca09837 dbd/db2/connection.c --- a/dbd/db2/connection.c Sat Jun 13 08:55:44 2009 +0000 +++ b/dbd/db2/connection.c Tue Sep 01 13:15:02 2009 +0000 @@ -230,6 +230,17 @@ return 0; } +/* + * __tostring + */ +static int connection_tostring(lua_State *L) { + connection_t *conn = (connection_t *)luaL_checkudata(L, 1, DBD_DB2_CONNECTION); + + lua_pushfstring(L, "%s: %p", DBD_DB2_CONNECTION, conn); + + return 1; +} + int dbd_db2_connection(lua_State *L) { static const luaL_Reg connection_methods[] = { {"autocommit", connection_autocommit}, @@ -255,6 +266,9 @@ lua_pushcfunction(L, connection_gc); lua_setfield(L, -2, "__gc"); + lua_pushcfunction(L, connection_tostring); + lua_setfield(L, -2, "__tostring"); + luaL_register(L, DBD_DB2_CONNECTION, connection_class_methods); return 1; diff -r 999ef93f0dbc -r 03ed0ca09837 dbd/db2/statement.c --- a/dbd/db2/statement.c Sat Jun 13 08:55:44 2009 +0000 +++ b/dbd/db2/statement.c Tue Sep 01 13:15:02 2009 +0000 @@ -447,6 +447,17 @@ return 0; } +/* + * __tostring + */ +static int statement_tostring(lua_State *L) { + statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_DB2_STATEMENT); + + lua_pushfstring(L, "%s: %p", DBD_DB2_STATEMENT, statement); + + return 1; +} + int dbd_db2_statement_create(lua_State *L, connection_t *conn, const char *sql_query) { SQLRETURN rc = SQL_SUCCESS; statement_t *statement = NULL; @@ -519,6 +530,9 @@ lua_pushcfunction(L, statement_gc); lua_setfield(L, -2, "__gc"); + lua_pushcfunction(L, statement_tostring); + lua_setfield(L, -2, "__tostring"); + luaL_register(L, DBD_DB2_STATEMENT, statement_class_methods); return 1; diff -r 999ef93f0dbc -r 03ed0ca09837 dbd/mysql/connection.c --- a/dbd/mysql/connection.c Sat Jun 13 08:55:44 2009 +0000 +++ b/dbd/mysql/connection.c Tue Sep 01 13:15:02 2009 +0000 @@ -187,6 +187,17 @@ return 0; } +/* + * __tostring + */ +static int connection_tostring(lua_State *L) { + connection_t *conn = (connection_t *)luaL_checkudata(L, 1, DBD_MYSQL_CONNECTION); + + lua_pushfstring(L, "%s: %p", DBD_MYSQL_CONNECTION, conn); + + return 1; +} + int dbd_mysql_connection(lua_State *L) { static const luaL_Reg connection_methods[] = { {"autocommit", connection_autocommit}, @@ -212,6 +223,9 @@ lua_pushcfunction(L, connection_gc); lua_setfield(L, -2, "__gc"); + lua_pushcfunction(L, connection_tostring); + lua_setfield(L, -2, "__tostring"); + luaL_register(L, DBD_MYSQL_CONNECTION, connection_class_methods); return 1; diff -r 999ef93f0dbc -r 03ed0ca09837 dbd/mysql/statement.c --- a/dbd/mysql/statement.c Sat Jun 13 08:55:44 2009 +0000 +++ b/dbd/mysql/statement.c Tue Sep 01 13:15:02 2009 +0000 @@ -402,6 +402,17 @@ return 0; } +/* + * __tostring + */ +static int statement_tostring(lua_State *L) { + statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_MYSQL_STATEMENT); + + lua_pushfstring(L, "%s: %p", DBD_MYSQL_STATEMENT, statement); + + return 1; +} + int dbd_mysql_statement_create(lua_State *L, connection_t *conn, const char *sql_query) { unsigned long sql_len = strlen(sql_query); @@ -456,6 +467,9 @@ lua_pushcfunction(L, statement_gc); lua_setfield(L, -2, "__gc"); + lua_pushcfunction(L, statement_tostring); + lua_setfield(L, -2, "__tostring"); + luaL_register(L, DBD_MYSQL_STATEMENT, statement_class_methods); return 1; diff -r 999ef93f0dbc -r 03ed0ca09837 dbd/oracle/connection.c --- a/dbd/oracle/connection.c Sat Jun 13 08:55:44 2009 +0000 +++ b/dbd/oracle/connection.c Tue Sep 01 13:15:02 2009 +0000 @@ -216,6 +216,17 @@ return 0; } +/* + * __tostring + */ +static int connection_tostring(lua_State *L) { + connection_t *conn = (connection_t *)luaL_checkudata(L, 1, DBD_ORACLE_CONNECTION); + + lua_pushfstring(L, "%s: %p", DBD_ORACLE_CONNECTION, conn); + + return 1; +} + int dbd_oracle_connection(lua_State *L) { /* * instance methods @@ -247,6 +258,9 @@ lua_pushcfunction(L, connection_gc); lua_setfield(L, -2, "__gc"); + lua_pushcfunction(L, connection_tostring); + lua_setfield(L, -2, "__tostring"); + luaL_register(L, DBD_ORACLE_CONNECTION, connection_class_methods); return 1; diff -r 999ef93f0dbc -r 03ed0ca09837 dbd/oracle/statement.c --- a/dbd/oracle/statement.c Sat Jun 13 08:55:44 2009 +0000 +++ b/dbd/oracle/statement.c Tue Sep 01 13:15:02 2009 +0000 @@ -475,6 +475,17 @@ return 0; } +/* + * __tostring + */ +static int statement_tostring(lua_State *L) { + statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_ORACLE_STATEMENT); + + lua_pushfstring(L, "%s: %p", DBD_ORACLE_STATEMENT, statement); + + return 1; +} + int dbd_oracle_statement_create(lua_State *L, connection_t *conn, const char *sql_query) { int rc; statement_t *statement = NULL; @@ -528,6 +539,9 @@ lua_pushcfunction(L, statement_gc); lua_setfield(L, -2, "__gc"); + lua_pushcfunction(L, statement_tostring); + lua_setfield(L, -2, "__tostring"); + luaL_register(L, DBD_ORACLE_STATEMENT, statement_class_methods); return 1; diff -r 999ef93f0dbc -r 03ed0ca09837 dbd/postgresql/connection.c --- a/dbd/postgresql/connection.c Sat Jun 13 08:55:44 2009 +0000 +++ b/dbd/postgresql/connection.c Tue Sep 01 13:15:02 2009 +0000 @@ -257,6 +257,17 @@ return 0; } +/* + * __tostring + */ +static int connection_tostring(lua_State *L) { + connection_t *conn = (connection_t *)luaL_checkudata(L, 1, DBD_POSTGRESQL_CONNECTION); + + lua_pushfstring(L, "%s: %p", DBD_POSTGRESQL_CONNECTION, conn); + + return 1; +} + int dbd_postgresql_connection(lua_State *L) { static const luaL_Reg connection_methods[] = { {"autocommit", connection_autocommit}, @@ -282,6 +293,9 @@ lua_pushcfunction(L, connection_gc); lua_setfield(L, -2, "__gc"); + lua_pushcfunction(L, connection_tostring); + lua_setfield(L, -2, "__tostring"); + luaL_register(L, DBD_POSTGRESQL_CONNECTION, connection_class_methods); return 1; diff -r 999ef93f0dbc -r 03ed0ca09837 dbd/postgresql/statement.c --- a/dbd/postgresql/statement.c Sat Jun 13 08:55:44 2009 +0000 +++ b/dbd/postgresql/statement.c Tue Sep 01 13:15:02 2009 +0000 @@ -350,6 +350,17 @@ return 0; } +/* + * __tostring + */ +static int statement_tostring(lua_State *L) { + statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_POSTGRESQL_STATEMENT); + + lua_pushfstring(L, "%s: %p", DBD_POSTGRESQL_STATEMENT, statement); + + return 1; +} + int dbd_postgresql_statement_create(lua_State *L, connection_t *conn, const char *sql_query) { statement_t *statement = NULL; ExecStatusType status; @@ -426,6 +437,9 @@ lua_pushcfunction(L, statement_gc); lua_setfield(L, -2, "__gc"); + lua_pushcfunction(L, statement_tostring); + lua_setfield(L, -2, "__tostring"); + luaL_register(L, DBD_POSTGRESQL_STATEMENT, statement_class_methods); return 1; diff -r 999ef93f0dbc -r 03ed0ca09837 dbd/sqlite3/connection.c --- a/dbd/sqlite3/connection.c Sat Jun 13 08:55:44 2009 +0000 +++ b/dbd/sqlite3/connection.c Tue Sep 01 13:15:02 2009 +0000 @@ -198,6 +198,17 @@ return 0; } +/* + * __tostring + */ +static int connection_tostring(lua_State *L) { + connection_t *conn = (connection_t *)luaL_checkudata(L, 1, DBD_SQLITE_CONNECTION); + + lua_pushfstring(L, "%s: %p", DBD_SQLITE_CONNECTION, conn); + + return 1; +} + int dbd_sqlite3_connection(lua_State *L) { /* * instance methods @@ -229,6 +240,9 @@ lua_pushcfunction(L, connection_gc); lua_setfield(L, -2, "__gc"); + lua_pushcfunction(L, connection_tostring); + lua_setfield(L, -2, "__tostring"); + luaL_register(L, DBD_SQLITE_CONNECTION, connection_class_methods); return 1; diff -r 999ef93f0dbc -r 03ed0ca09837 dbd/sqlite3/statement.c --- a/dbd/sqlite3/statement.c Sat Jun 13 08:55:44 2009 +0000 +++ b/dbd/sqlite3/statement.c Tue Sep 01 13:15:02 2009 +0000 @@ -342,6 +342,17 @@ return 0; } +/* + * __tostring + */ +static int statement_tostring(lua_State *L) { + statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_SQLITE_STATEMENT); + + lua_pushfstring(L, "%s: %p", DBD_SQLITE_STATEMENT, statement); + + return 1; +} + int dbd_sqlite3_statement_create(lua_State *L, connection_t *conn, const char *sql_query) { statement_t *statement = NULL; @@ -386,6 +397,9 @@ lua_pushcfunction(L, statement_gc); lua_setfield(L, -2, "__gc"); + lua_pushcfunction(L, statement_tostring); + lua_setfield(L, -2, "__tostring"); + luaL_register(L, DBD_SQLITE_STATEMENT, statement_class_methods); return 1;