Date: Wednesday, December 14, 2005 @ 15:18:23
Author: zsolt
Path: /cvsroot/carob/libmysequoia
Modified: include/CarobMySQL.hpp (1.10 -> 1.11) src/CarobMySQL.cpp (1.16
-> 1.17) src/MySQLAPI.cpp (1.13 -> 1.14)
- changed function name from mysql_list_tables to list_tables
- implemented:
- CarobMYSQL::set_autocommit
- CarobMYSQL::commit
- CarobMYSQL::rollback
- CarobMYSQL::list_table_fields
- CarobMYSQL::list_databases
- CarobMYSQL::list_tables
- mysql_autocommit
- mysql_commit
- mysql_rollback
- mysql_create_db
- mysql_drop_db
- mysql_refresh
- mysql_get_client_info
- mysql_get_client_version
- mysql_get_host_info
- mysql_get_server_info
- mysql_get_server_version
- mysql_get_proto_info
- mysql_info
- mysql_list_dbs
- mysql_list_fields
- mysql_list_tables
- replaced tab character with space in file MySQLAPI.cpp
------------------------+
include/CarobMySQL.hpp | 6 +
src/CarobMySQL.cpp | 89 ++++++++++++++++++++--
src/MySQLAPI.cpp | 184 ++++++++++++++++++++++++++++-------------------
3 files changed, 197 insertions(+), 82 deletions(-)
Index: libmysequoia/include/CarobMySQL.hpp
diff -u libmysequoia/include/CarobMySQL.hpp:1.10
libmysequoia/include/CarobMySQL.hpp:1.11
--- libmysequoia/include/CarobMySQL.hpp:1.10 Tue Dec 13 14:09:45 2005
+++ libmysequoia/include/CarobMySQL.hpp Wed Dec 14 15:18:23 2005
@@ -33,6 +33,10 @@
const unsigned long MYSEQUOIA_MAGIC = 0xC00CA10B;
+#define CAROB_MYSQL_CLIENT_INFO "5.0.15";
+#define CAROB_MYSQL_CLIENT_VERSION 50015;
+#define PROTOCOL_VERSION 10
+
class CarobMYSQL
{
public:
@@ -179,7 +183,7 @@
* @param wild a regular expression matching the tables names
* @return MYSQL_RES with the name of the tables
*/
- MYSQL_RES *mysql_list_tables(const char *wild);
+ MYSQL_RES *list_tables(const char *wild);
/**
* Returns a pointer to the MYSQL structure
Index: libmysequoia/src/CarobMySQL.cpp
diff -u libmysequoia/src/CarobMySQL.cpp:1.16
libmysequoia/src/CarobMySQL.cpp:1.17
--- libmysequoia/src/CarobMySQL.cpp:1.16 Tue Dec 13 14:09:44 2005
+++ libmysequoia/src/CarobMySQL.cpp Wed Dec 14 15:18:23 2005
@@ -39,8 +39,9 @@
mysql->free_me = free_me;
//TODO maybe a real server version string ???
mysql->server_version = "50015";
+ mysql->protocol_version = PROTOCOL_VERSION;
// TODO fill in other required mysql fields
-
+
mysqlPtr = mysql;
connectionPool = &ConnectionPool::getInstance();
@@ -55,6 +56,7 @@
FREE_AND_NULL_ARRAY(mysqlPtr->passwd);
FREE_AND_NULL_ARRAY(mysqlPtr->db);
FREE_AND_NULL_ARRAY(mysqlPtr->host_info);
+ FREE_AND_NULL_ARRAY(mysqlPtr->info);
mysqlPtr->thd = 0;
mysqlPtr->extra_info = 0;
@@ -154,7 +156,7 @@
bool
CarobMYSQL::real_query (const char *query, ulong length)
{
- if (mysqlPtr->status != MYSQL_STATUS_READY)
+ if (mysqlPtr->status != MYSQL_STATUS_READY || !connectionPtr)
{
set_error(CR_COMMANDS_OUT_OF_SYNC, SQLT_UNKNOWN);
return 0;
@@ -167,11 +169,17 @@
{
mysqlPtr->affected_rows = 0;
mysqlPtr->status = MYSQL_STATUS_GET_RESULT;
+ FREE_AND_NULL_ARRAY(mysqlPtr->info);
}
else
{
mysqlPtr->affected_rows = stmtPtr->getUpdateCount();
mysqlPtr->status = MYSQL_STATUS_READY;
+
+ char info[100];
+ snprintf(info, sizeof(info), "Records: %llu Duplicates: 0 Warnings: 0",
mysqlPtr->affected_rows);
+ info[sizeof(info)-1] = 0;
+ mysqlPtr->info = cstrdup(info);
}
return true;
@@ -357,37 +365,100 @@
bool
CarobMYSQL::set_autocommit (const my_bool mode)
{
- return 0;
+ if (mysqlPtr->status != MYSQL_STATUS_READY || !connectionPtr)
+ {
+ set_error(CR_COMMANDS_OUT_OF_SYNC, SQLT_UNKNOWN);
+ return 0;
+ }
+
+ try
+ {
+ connectionPtr->setAutoCommit(mode);
+ return true;
+ }
+ catch (CarobException &e)
+ {
+ set_error(e.getErrorCode(), toString(e.description()).c_str(),
toString(e.getSQLState()).c_str());
+ return 0;
+ }
}
bool
CarobMYSQL::commit ()
{
- return 0;
+ if (mysqlPtr->status != MYSQL_STATUS_READY || !connectionPtr)
+ {
+ set_error(CR_COMMANDS_OUT_OF_SYNC, SQLT_UNKNOWN);
+ return 0;
+ }
+
+ try
+ {
+ connectionPtr->commit();
+ return true;
+ }
+ catch (CarobException &e)
+ {
+ set_error(e.getErrorCode(), toString(e.description()).c_str(),
toString(e.getSQLState()).c_str());
+ return 0;
+ }
}
bool
CarobMYSQL::rollback ()
{
- return 0;
+ if (mysqlPtr->status != MYSQL_STATUS_READY || !connectionPtr)
+ {
+ set_error(CR_COMMANDS_OUT_OF_SYNC, SQLT_UNKNOWN);
+ return 0;
+ }
+
+ try
+ {
+ connectionPtr->rollback();
+ return true;
+ }
+ catch (CarobException &e)
+ {
+ set_error(e.getErrorCode(), toString(e.description()).c_str(),
toString(e.getSQLState()).c_str());
+ return 0;
+ }
}
MYSQL_RES *
CarobMYSQL::list_table_fields (const char *table, const char *wild)
{
- return 0;
+ std::string query=std::string("SHOW FIELDS FROM ")+table;
+ if (wild)
+ query = query + " LIKE '"+wild+"'";
+ if (real_query(query.c_str(),query.length()))
+ return get_results(true);
+ else
+ return 0;
}
MYSQL_RES *
CarobMYSQL::list_databases (const char *wild)
{
- return 0;
+ std::string query="SHOW DATABASES";
+ if (wild)
+ query = query + " LIKE '"+wild+"'";
+ if (real_query(query.c_str(),query.length()))
+ return get_results(true);
+ else
+ return 0;
}
MYSQL_RES *
-CarobMYSQL::mysql_list_tables (const char *wild)
+CarobMYSQL::list_tables (const char *wild)
{
- return 0;
+ std::string query="SHOW TABLES";
+ if (wild)
+ query = query + "LIKE '"+wild+"'";
+ if (real_query(query.c_str(),query.length()))
+ return get_results(true);
+ else
+ return 0;
}
MYSQL *
Index: libmysequoia/src/MySQLAPI.cpp
diff -u libmysequoia/src/MySQLAPI.cpp:1.13 libmysequoia/src/MySQLAPI.cpp:1.14
--- libmysequoia/src/MySQLAPI.cpp:1.13 Tue Dec 13 14:09:44 2005
+++ libmysequoia/src/MySQLAPI.cpp Wed Dec 14 15:18:23 2005
@@ -98,7 +98,7 @@
int STDCALL
mysql_server_init (int argc, char **argv, char **groups)
{
- return 0;
+ return 0;
}
/* Finalize the MYSQL client library. */
@@ -112,7 +112,7 @@
/* Connects to a MySQL server. This function is deprecated; use
mysql_real_connect() instead. */
MYSQL *STDCALL
mysql_connect (MYSQL * mysql, const char *host, const char *user,
- const char *passwd)
+ const char *passwd)
{
if (mysql)
{
@@ -132,8 +132,8 @@
*/
MYSQL *STDCALL
mysql_real_connect (MYSQL * mysql, const char *host, const char *user,
- const char *passwd, const char *db, unsigned int port,
- const char *unix_socket, unsigned long clientflag)
+ const char *passwd, const char *db, unsigned int port,
+ const char *unix_socket, unsigned long clientflag)
{
if (mysql)
{
@@ -158,7 +158,7 @@
/* Changes user and database on an open connection. */
my_bool STDCALL
mysql_change_user (MYSQL * mysql, const char *user, const char *passwd,
- const char *db)
+ const char *db)
{
if (mysql)
{
@@ -172,13 +172,13 @@
int STDCALL
mysql_options (MYSQL * mysql, enum mysql_option option, const char *arg)
{
- return 0;
+ return 0;
}
int STDCALL
mysql_ping (MYSQL * mysql)
{
- return 0;
+ return 0;
}
/* Query functions */
@@ -258,19 +258,19 @@
my_bool STDCALL
mysql_eof (MYSQL_RES * res)
{
- return 0;
+ return 0;
}
my_bool STDCALL
mysql_more_results (MYSQL * mysql)
{
- return 0;
+ return 0;
}
int STDCALL
mysql_next_result (MYSQL * mysql)
{
- return 0;
+ return 0;
}
/* Seeks to an arbitrary row number in a query result set. */
@@ -332,7 +332,7 @@
MYSQL_FIELD *STDCALL
mysql_fetch_fields (MYSQL_RES * res)
{
- return res ? res->fields : 0;
+ return res ? res->fields : 0;
}
/* Returns the lengths of all columns in the current row. */
@@ -388,14 +388,14 @@
unsigned int STDCALL
mysql_field_count (MYSQL * mysql)
{
- return mysql ? mysql->field_count : 0;
+ return mysql ? mysql->field_count : 0;
}
/* Returns the position of the field cursor used for the last
mysql_fetch_field(). */
MYSQL_FIELD_OFFSET STDCALL
mysql_field_tell (MYSQL_RES * res)
{
- return res ? res->current_field : 0;
+ return res ? res->current_field : 0;
}
/* Returns the number of columns in a result set. */
@@ -422,7 +422,7 @@
my_ulonglong STDCALL
mysql_insert_id (MYSQL * mysql)
{
- return 0;
+ return 0;
}
/* Error handling */
@@ -451,7 +451,7 @@
unsigned int STDCALL
mysql_warning_count (MYSQL * mysql)
{
- return 0;
+ return 0;
}
void STDCALL
@@ -464,140 +464,180 @@
unsigned long STDCALL
mysql_escape_string (char *to, const char *from, unsigned long from_length)
{
- return 0;
+ return 0;
}
unsigned long STDCALL
mysql_real_escape_string (MYSQL * mysql, char *to, const char *from,
- unsigned long length)
+ unsigned long length)
{
- return 0;
+ return 0;
}
const char *
mysql_character_set_name (MYSQL * mysql)
{
- return 0;
+ return 0;
}
/* Transaction support */
+/* Toggles autocommit mode on/off. */
my_bool STDCALL
mysql_autocommit (MYSQL * mysql, my_bool auto_mode)
{
- return 0;
+ return mysql ? getCarob(mysql)->set_autocommit(auto_mode) : 0;
}
+/* Commits the transaction. */
my_bool STDCALL
mysql_commit (MYSQL * mysql)
{
- return 0;
+ return mysql ? getCarob(mysql)->commit() : 0;
}
+/* Rolls back the transaction. */
my_bool STDCALL
mysql_rollback (MYSQL * mysql)
{
- return 0;
+ return mysql ? getCarob(mysql)->rollback() : 0;
}
/* Server management */
+/* Creates a database. This function is deprecated; use the SQL statement
CREATE DATABASE instead. */
int STDCALL
mysql_create_db (MYSQL * mysql, const char *DB)
{
- return 0;
+ std::string query=std::string("CREATE DATABASE ")+DB;
+ return mysql_real_query(mysql, query.data(), query.length());
}
+/* Drops a database. This function is deprecated; use the SQL statement DROP
DATABASE instead. */
int STDCALL
mysql_drop_db (MYSQL * mysql, const char *DB)
{
- return 0;
+ std::string query=std::string("DROP DATABASE ")+DB;
+ return mysql_real_query(mysql, query.data(), query.length());
}
int STDCALL
mysql_shutdown (MYSQL * mysql, enum mysql_enum_shutdown_level shutdown_level)
{
- return 0;
+ return 0;
}
+/* Flush or reset tables and caches. */
int STDCALL
mysql_refresh (MYSQL * mysql, unsigned int refresh_options)
{
- return 0;
+ int result = 0;
+
+ if (refresh_options & REFRESH_GRANT)
+ result = mysql_real_query(mysql, "FLUSH PRIVILEGES", 16);
+ if (!result && refresh_options & REFRESH_LOG)
+ result = mysql_real_query(mysql, "FLUSH LOGS", 10);
+ if (!result && refresh_options & REFRESH_TABLES)
+ result = mysql_real_query(mysql, "FLUSH TABLES", 12);
+ if (!result && refresh_options & REFRESH_HOSTS)
+ result = mysql_real_query(mysql, "FLUSH HOSTS", 11);
+ if (!result && refresh_options & REFRESH_STATUS)
+ result = mysql_real_query(mysql, "FLUSH STATUS", 12);
+
+ return result;
}
/* Metadata */
+/* Returns client version information as a string. */
const char *STDCALL
mysql_get_client_info (void)
{
- return 0;
+ return CAROB_MYSQL_CLIENT_INFO;
}
+/* Returns client version information as an integer. */
unsigned long STDCALL
mysql_get_client_version (void)
{
- return 0;
+ return CAROB_MYSQL_CLIENT_VERSION;
}
+/* Returns a string describing the connection. */
const char *STDCALL
mysql_get_host_info (MYSQL * mysql)
{
- return 0;
+ return mysql ? mysql->host_info : 0;
}
+/* Returns a string that represents the server version number. */
const char *
mysql_get_server_info (MYSQL * mysql)
{
- return 0;
+ return mysql ? mysql->server_version : 0;
}
+/* Returns version number of server as an integer. */
unsigned long STDCALL
mysql_get_server_version (MYSQL * mysql)
{
- return 0;
+ if (mysql)
+ {
+ unsigned long res = 0, multiply = 10000;
+ char *p=mysql->server_version, *end;
+ for (p=mysql->server_version; multiply > 0; multiply /= 100, p = end + 1)
+ res += strtoul(p,&end,10) * multiply;
+ return res;
+ }
+ else
+ return 0;
}
+/* Returns the protocol version used by the connection. */
unsigned int STDCALL
mysql_get_proto_info (MYSQL * mysql)
{
- return 0;
+ return mysql ? mysql->protocol_version : 0;
}
+/* Returns information about the most recently executed query. */
const char *STDCALL
mysql_info (MYSQL * mysql)
{
- return 0;
+ return mysql ? mysql->info : 0;
}
+/* Returns database names matching a simple regular expression. */
MYSQL_RES *STDCALL
mysql_list_dbs (MYSQL * mysql, const char *wild)
{
- return 0;
+ return mysql ? getCarob(mysql)->list_databases(wild) : 0;
}
+/* Returns field names matching a simple regular expression. */
MYSQL_RES *STDCALL
mysql_list_fields (MYSQL * mysql, const char *table, const char *wild)
{
- return 0;
+ return mysql ? getCarob(mysql)->list_table_fields(table, wild) : 0;
}
MYSQL_RES *STDCALL
mysql_list_processes (MYSQL * mysql)
{
- return 0;
+ return 0;
}
+/* Returns table names matching a simple regular expression. */
MYSQL_RES *STDCALL
mysql_list_tables (MYSQL * mysql, const char *wild)
{
- return 0;
+ return mysql ? getCarob(mysql)->list_tables(wild) : 0;
}
const char *STDCALL
mysql_stat (MYSQL * mysql)
{
- return 0;
+ return 0;
}
/* Thread functions */
@@ -605,7 +645,7 @@
my_bool
mysql_thread_init (void)
{
- return 0;
+ return 0;
}
void
@@ -616,13 +656,13 @@
unsigned long STDCALL
mysql_thread_id (MYSQL * mysql)
{
- return 0;
+ return 0;
}
unsigned int STDCALL
mysql_thread_safe (void)
{
- return 0;
+ return 0;
}
/* Prepared statements */
@@ -630,39 +670,39 @@
my_ulonglong
mysql_stmt_affected_rows (MYSQL_STMT * stmt)
{
- return 0;
+ return 0;
}
my_bool
mysql_stmt_attr_get (MYSQL_STMT * stmt, enum enum_stmt_attr_type option,
- void *arg)
+ void *arg)
{
- return 0;
+ return 0;
}
my_bool
mysql_stmt_attr_set (MYSQL_STMT * stmt, enum enum_stmt_attr_type option,
- const void *arg)
+ const void *arg)
{
- return 0;
+ return 0;
}
my_bool
mysql_stmt_bind_param (MYSQL_STMT * stmt, MYSQL_BIND * bind)
{
- return 0;
+ return 0;
}
my_bool
mysql_stmt_bind_result (MYSQL_STMT * stmt, MYSQL_BIND * bind)
{
- return 0;
+ return 0;
}
my_bool
mysql_stmt_close (MYSQL_STMT *)
{
- return 0;
+ return 0;
}
void
@@ -673,122 +713,122 @@
unsigned int
mysql_stmt_errno (MYSQL_STMT * stmt)
{
- return 0;
+ return 0;
}
const char *
mysql_stmt_error (MYSQL_STMT * stmt)
{
- return 0;
+ return 0;
}
int
mysql_stmt_execute (MYSQL_STMT * stmt)
{
- return 0;
+ return 0;
}
int
mysql_stmt_fetch (MYSQL_STMT * stmt)
{
- return 0;
+ return 0;
}
int
mysql_stmt_fetch_column (MYSQL_STMT * stmt, MYSQL_BIND * bind,
- unsigned int column, unsigned long offset)
+ unsigned int column, unsigned long offset)
{
- return 0;
+ return 0;
}
unsigned int
mysql_stmt_field_count (MYSQL_STMT * stmt)
{
- return 0;
+ return 0;
}
my_bool
mysql_stmt_free_result (MYSQL_STMT * stmt)
{
- return 0;
+ return 0;
}
MYSQL_STMT *
mysql_stmt_init (MYSQL * mysql)
{
- return 0;
+ return 0;
}
my_ulonglong
mysql_stmt_insert_id (MYSQL_STMT * stmt)
{
- return 0;
+ return 0;
}
my_ulonglong
mysql_stmt_num_rows (MYSQL_STMT * stmt)
{
- return 0;
+ return 0;
}
unsigned long
mysql_stmt_param_count (MYSQL_STMT * stmt)
{
- return 0;
+ return 0;
}
MYSQL_RES *
mysql_stmt_param_metadata (MYSQL_STMT * stmt)
{
- return 0;
+ return 0;
}
int
mysql_stmt_prepare (MYSQL_STMT * stmt, const char *query,
- unsigned long length)
+ unsigned long length)
{
- return 0;
+ return 0;
}
my_bool
mysql_stmt_reset (MYSQL_STMT * stmt)
{
- return 0;
+ return 0;
}
MYSQL_RES *
mysql_stmt_result_metadata (MYSQL_STMT * stmt)
{
- return 0;
+ return 0;
}
MYSQL_ROW_OFFSET
mysql_stmt_row_seek (MYSQL_STMT * stmt, MYSQL_ROW_OFFSET offset)
{
- return 0;
+ return 0;
}
MYSQL_ROW_OFFSET
mysql_stmt_row_tell (MYSQL_STMT * stmt)
{
- return 0;
+ return 0;
}
my_bool
mysql_stmt_send_long_data (MYSQL_STMT * stmt, unsigned int parameter_number,
- const char *data, unsigned long length)
+ const char *data, unsigned long length)
{
- return 0;
+ return 0;
}
const char *
mysql_stmt_sqlstate (MYSQL_STMT * stmt)
{
- return 0;
+ return 0;
}
int
mysql_stmt_store_result (MYSQL_STMT * stmt)
{
- return 0;
+ return 0;
}
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits