Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

CVS update of libmysequoia/src (CarobMySQL.cpp CarobStmt.cpp): msg#00146

db.carob.cvs

Subject: CVS update of libmysequoia/src (CarobMySQL.cpp CarobStmt.cpp)

Date: Friday, March 24, 2006 @ 14:00:37
Author: zsolt
Path: /cvsroot/carob/libmysequoia/src

Modified: CarobMySQL.cpp (1.65 -> 1.66) CarobStmt.cpp (1.29 -> 1.30)

ConverterException is now caught and treated correctly.


----------------+
CarobMySQL.cpp | 538 ++++++++++++++++++++++++++++++-------------------------
CarobStmt.cpp | 281 ++++++++++++++++------------
2 files changed, 465 insertions(+), 354 deletions(-)


Index: libmysequoia/src/CarobMySQL.cpp
diff -u libmysequoia/src/CarobMySQL.cpp:1.65
libmysequoia/src/CarobMySQL.cpp:1.66
--- libmysequoia/src/CarobMySQL.cpp:1.65 Fri Mar 24 10:02:40 2006
+++ libmysequoia/src/CarobMySQL.cpp Fri Mar 24 14:00:37 2006
@@ -154,7 +154,7 @@
if (!passwd)
passwd = "";
}
-
+
if (!port)
{
port = mysqlPtr->options.port;
@@ -162,80 +162,89 @@
port = 25322;
}

- /* set the default character set if not set */
- if (!mysqlPtr->options.charset_name || !*mysqlPtr->options.charset_name)
- {
- mysqlPtr->options.charset_name = cstrdup("latin1");
- }
- /* send it to the server */
- conv.set_code(mysqlPtr->options.charset_name);
-
- /* Check for delayed connection. If db name not given, the connection can't
happen, because sequoia doesn't support it.
- * The real connection will happen after the user call the command
mysql_select_db or mysql_real_connect */
- if (!db || !*db)
+ try
{
- db = mysqlPtr->options.db;
- if (!db || !*db)
+ /* set the default character set if not set */
+ if (!mysqlPtr->options.charset_name || !*mysqlPtr->options.charset_name)
{
- delete_connection();
- set_connect_info(host, user, passwd, 0, port);
-
- LOG4CXX_DEBUG(logger, "Leaving connect (delayed connection.)");
- return true;
+ mysqlPtr->options.charset_name = cstrdup("latin1");
}
- }
-
- try
- {
- HostTokenizer ht(host);
- HostTokenizer::const_iterator hti = ht.begin();
-
- LOG4CXX_DEBUG(logger, "Connect (first host): host=" << hti->host << "
port=" << hti->port);
- port = hti->port;
- ConnectionParameters connectionParameters(to_wstring(hti->host),
hti->port,
- to_wstring(db), to_wstring(user), to_wstring(passwd), DEBUG_LEVEL_OFF,
ht.getPolicy(), DEFAULT_RETRY_INTERVAL, true);
- hti++;
+ /* send it to the server */
+ conv.set_code(mysqlPtr->options.charset_name);

- for (; hti != ht.end(); hti++)
+ /* Check for delayed connection. If db name not given, the connection
can't happen, because sequoia doesn't support it.
+ * The real connection will happen after the user call the command
mysql_select_db or mysql_real_connect */
+ if (!db || !*db)
{
- connectionParameters.addController(to_wstring(hti->host), hti->port);
- LOG4CXX_DEBUG(logger, "Connect (adding host): host=" << hti->host << "
port=" << hti->port);
- }
+ db = mysqlPtr->options.db;
+ if (!db || !*db)
+ {
+ delete_connection();
+ set_connect_info(host, user, passwd, 0, port);

- Connection *newConnectionPtr = new Connection(connectionParameters);
+ LOG4CXX_DEBUG(logger, "Leaving connect (delayed connection.)");
+ return true;
+ }
+ }

- if (newConnectionPtr)
+ try
{
- //TODO handle not enough memory
- delete_connection();
- set_connect_info(host, user, passwd, db, port);
-
- LOG4CXX_INFO(logger, "Connected: host=" << host << " user=" << user << "
passwd=" << passwd << " db=" << db << " port=" << port);
+ HostTokenizer ht(host);
+ HostTokenizer::const_iterator hti = ht.begin();

- reset_error();
-
- connectionPtr = newConnectionPtr;
+ LOG4CXX_DEBUG(logger, "Connect (first host): host=" << hti->host << "
port=" << hti->port);
+ port = hti->port;
+ ConnectionParameters connectionParameters(to_wstring(hti->host),
hti->port,
+ to_wstring(db), to_wstring(user), to_wstring(passwd), DEBUG_LEVEL_OFF,
ht.getPolicy(), DEFAULT_RETRY_INTERVAL, true);
+ hti++;
+
+ for (; hti != ht.end(); hti++)
+ {
+ connectionParameters.addController(to_wstring(hti->host), hti->port);
+ LOG4CXX_DEBUG(logger, "Connect (adding host): host=" << hti->host << "
port=" << hti->port);
+ }
+
+ Connection *newConnectionPtr = new Connection(connectionParameters);

- //try to execute the initial commands after each connection
- std::vector<std::string>::const_iterator iter;
- for (iter=init_cmd_list.begin(); iter != init_cmd_list.end(); iter++)
- real_query(iter->data(), iter->length());
+ if (newConnectionPtr)
+ {
+ //TODO handle not enough memory
+ delete_connection();
+ set_connect_info(host, user, passwd, db, port);
+
+ LOG4CXX_INFO(logger, "Connected: host=" << host << " user=" << user <<
" passwd=" << passwd << " db=" << db << " port=" << port);
+
+ reset_error();
+
+ connectionPtr = newConnectionPtr;
+
+ //try to execute the initial commands after each connection
+ std::vector<std::string>::const_iterator iter;
+ for (iter=init_cmd_list.begin(); iter != init_cmd_list.end(); iter++)
+ real_query(iter->data(), iter->length());
+ }
+
+ LOG4CXX_DEBUG(logger, "Leaving connect.");
+ return true;
+ }
+ catch (CarobException &e)
+ {
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ //TODO error handling
+ LOG4CXX_DEBUG(logger, "Leaving connect.");
+ return false;
+ }
+ catch (HostTokenizerException &e)
+ {
+ set_error(0, e.description().c_str(), error_sqlstate[SQLT_UNKNOWN]);
+ //TODO error handling
+ LOG4CXX_DEBUG(logger, "Leaving connect.");
+ return false;
}
-
- LOG4CXX_DEBUG(logger, "Leaving connect.");
- return true;
- }
- catch (CarobException &e)
- {
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
- //TODO error handling
- LOG4CXX_DEBUG(logger, "Leaving connect.");
- return false;
}
- catch (HostTokenizerException &e)
+ catch (ConverterException &e)
{
set_error(0, e.description().c_str(), error_sqlstate[SQLT_UNKNOWN]);
- //TODO error handling
LOG4CXX_DEBUG(logger, "Leaving connect.");
return false;
}
@@ -285,60 +294,68 @@
LOG4CXX_DEBUG(logger, "Leaving real_query: result=0");
return false;
}
-
- try {
- drsPtr = NULL;
-
- if (!stmtPtr)
- {
- stmtPtr = connectionPtr->createStatement();
- stmtPtr->setQueryTimeout(mysqlPtr->options.read_timeout);
- stmtPtr->setFetchSize(1);
- }

- FREE_AND_NULL_ARRAY(mysqlPtr->info);
-
- if (stmtPtr->execute(to_wstring(std::string(query,length))))
- {
- mysqlPtr->affected_rows = 0;
- drsPtr = stmtPtr->getResultSet();
- mysqlPtr->field_count = drsPtr ? drsPtr->getNumberOfColumns() : 0;
- mysqlPtr->status = MYSQL_STATUS_GET_RESULT;
- LOG4CXX_INFO(logger, "Executed query with result set. Field_count=" <<
mysqlPtr->field_count);
- }
- else
- {
- mysqlPtr->affected_rows = stmtPtr->getUpdateCount();
- mysqlPtr->status = MYSQL_STATUS_READY;
- mysqlPtr->field_count = 0;
-
- 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);
- LOG4CXX_INFO(logger, "Executed query. Affected_rows=" <<
mysqlPtr->affected_rows);
-
- //if there are no affected rows, the query need to be parsed, to see if
not a "set names ..." type
- if (parse && mysqlPtr->affected_rows == 0)
+ try {
+ try {
+ drsPtr = NULL;
+
+ if (!stmtPtr)
{
- const char *p = query, *q = 0;
- if (string_match(p, "set") && string_match(p, "names") && (q =
get_next_string(p)) && (p - q < MAX_CHARSET_LEN))
+ stmtPtr = connectionPtr->createStatement();
+ stmtPtr->setQueryTimeout(mysqlPtr->options.read_timeout);
+ stmtPtr->setFetchSize(1);
+ }
+
+ FREE_AND_NULL_ARRAY(mysqlPtr->info);
+
+ if (stmtPtr->execute(to_wstring(std::string(query,length))))
+ {
+ mysqlPtr->affected_rows = 0;
+ drsPtr = stmtPtr->getResultSet();
+ mysqlPtr->field_count = drsPtr ? drsPtr->getNumberOfColumns() : 0;
+ mysqlPtr->status = MYSQL_STATUS_GET_RESULT;
+ LOG4CXX_INFO(logger, "Executed query with result set. Field_count=" <<
mysqlPtr->field_count);
+ }
+ else
+ {
+ mysqlPtr->affected_rows = stmtPtr->getUpdateCount();
+ mysqlPtr->status = MYSQL_STATUS_READY;
+ mysqlPtr->field_count = 0;
+
+ 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);
+ LOG4CXX_INFO(logger, "Executed query. Affected_rows=" <<
mysqlPtr->affected_rows);
+
+ //if there are no affected rows, the query need to be parsed, to see
if not a "set names ..." type
+ if (parse && mysqlPtr->affected_rows == 0)
{
- char charset[MAX_CHARSET_LEN+1];
- strncpy(charset,q,p-q); charset[p-q]=0;
- set_character_set(charset, false);
+ const char *p = query, *q = 0;
+ if (string_match(p, "set") && string_match(p, "names") && (q =
get_next_string(p)) && (p - q < MAX_CHARSET_LEN))
+ {
+ char charset[MAX_CHARSET_LEN+1];
+ strncpy(charset,q,p-q); charset[p-q]=0;
+ set_character_set(charset, false);
+ }
}
}
+
+ reset_error();
+
+ LOG4CXX_DEBUG(logger, "Leaving real_query: result=1");
+ return true;
+ }
+ catch (CarobException &e)
+ {
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ LOG4CXX_DEBUG(logger, "Leaving real_query: result=0");
+ return false;
}
-
- reset_error();
-
- LOG4CXX_DEBUG(logger, "Leaving real_query: result=1");
- return true;
}
- catch (CarobException &e)
+ catch (ConverterException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ set_error(0, e.description().c_str(), error_sqlstate[SQLT_UNKNOWN]);
LOG4CXX_DEBUG(logger, "Leaving real_query: result=0");
return false;
}
@@ -359,79 +376,87 @@
}

try {
- if (stmtPtr)
- {
- MYSQL_RES *result = 0;
-
-// drsPtr = stmtPtr->getResultSet();
- if (drsPtr)
+ try {
+ if (stmtPtr)
{
- //TODO handle not enough memory (std::nothrow)
- result = new MYSQL_RES;
- memset(result, 0, sizeof(MYSQL_RES));
-
- //Fill the fields metadata
- ResultSetMetaData rsmd(drsPtr);
- result->field_count = get_query_fields(result->fields, &rsmd);
- result->handle = mysqlPtr;
- result->lengths = new unsigned long[result->field_count];
+ MYSQL_RES *result = 0;

- //Fetch the rows if fetch_all was specified
- if (fetch_all)
+ // drsPtr = stmtPtr->getResultSet();
+ if (drsPtr)
{
- result->data = new MYSQL_DATA;
- memset(result->data, 0, sizeof(MYSQL_DATA));
- result->data->fields = result->field_count;
- MYSQL_ROWS *prev = 0;
- //Fetch row by row and allocate memory for each row
- while (drsPtr->next())
+ //TODO handle not enough memory (std::nothrow)
+ result = new MYSQL_RES;
+ memset(result, 0, sizeof(MYSQL_RES));
+
+ //Fill the fields metadata
+ ResultSetMetaData rsmd(drsPtr);
+ result->field_count = get_query_fields(result->fields, &rsmd);
+ result->handle = mysqlPtr;
+ result->lengths = new unsigned long[result->field_count];
+
+ //Fetch the rows if fetch_all was specified
+ if (fetch_all)
{
- MYSQL_ROWS *row = new MYSQL_ROWS;
- memset(row,0,sizeof(MYSQL_ROWS));
- alloc_row_data(row->data, result->fields, result->field_count,
row->length, result->lengths);
- if (prev)
- prev->next = row;
- else
- result->data->data = row;
- prev = row;
- result->data->rows++;
+ result->data = new MYSQL_DATA;
+ memset(result->data, 0, sizeof(MYSQL_DATA));
+ result->data->fields = result->field_count;
+ MYSQL_ROWS *prev = 0;
+ //Fetch row by row and allocate memory for each row
+ while (drsPtr->next())
+ {
+ MYSQL_ROWS *row = new MYSQL_ROWS;
+ memset(row,0,sizeof(MYSQL_ROWS));
+ alloc_row_data(row->data, result->fields, result->field_count,
row->length, result->lengths);
+ if (prev)
+ prev->next = row;
+ else
+ result->data->data = row;
+ prev = row;
+ result->data->rows++;
+ }
+ result->row_count=result->data->rows;
+ result->data_cursor = result->data->data;
+ mysqlPtr->status = MYSQL_STATUS_READY;
+
+ //Release the Carob dataset
+ //stmtPtr->close();
+ drsPtr->close();
+ drsPtr = 0;
}
- result->row_count=result->data->rows;
- result->data_cursor = result->data->data;
- mysqlPtr->status = MYSQL_STATUS_READY;
-
- //Release the Carob dataset
- //stmtPtr->close();
- drsPtr->close();
- drsPtr = 0;
+ else
+ {
+ //TODO check when to free the main internal liveResultPtr
+ liveResultPtr = result;
+ mysqlPtr->status = MYSQL_STATUS_USE_RESULT;
+ }
+
+ mysqlPtr->field_count = result->field_count;
+ mysqlPtr->affected_rows = result->row_count;
+ mysqlPtr->fields = result->fields;
+
+ reset_error();
}
+ #ifdef MYSQL5
else
- {
- //TODO check when to free the main internal liveResultPtr
- liveResultPtr = result;
- mysqlPtr->status = MYSQL_STATUS_USE_RESULT;
- }
-
- mysqlPtr->field_count = result->field_count;
- mysqlPtr->affected_rows = result->row_count;
- mysqlPtr->fields = result->fields;
-
- reset_error();
+ set_error(CR_NO_RESULT_SET, SQLT_UNKNOWN);
+ #endif
+
+ LOG4CXX_DEBUG(logger, "Leaving get_results: result=" << result);
+ return result;
}
-#ifdef MYSQL5
- else
- set_error(CR_NO_RESULT_SET, SQLT_UNKNOWN);
-#endif
-
- LOG4CXX_DEBUG(logger, "Leaving get_results: result=" << result);
- return result;
+ LOG4CXX_DEBUG(logger, "Leaving get_results: result=0");
+ return 0;
+ }
+ catch (CarobException &e)
+ {
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ LOG4CXX_DEBUG(logger, "Leaving get_results: result=0");
+ return 0;
}
- LOG4CXX_DEBUG(logger, "Leaving get_results: result=0");
- return 0;
}
- catch (CarobException &e)
+ catch (ConverterException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ set_error(0, e.description().c_str(), error_sqlstate[SQLT_UNKNOWN]);
LOG4CXX_DEBUG(logger, "Leaving get_results: result=0");
return 0;
}
@@ -497,19 +522,27 @@

try
{
- if (stmtPtr->getMoreResults() || stmtPtr->getUpdateCount() != -1)
+ try
{
- result = 0;
- mysqlPtr->affected_rows = stmtPtr->getUpdateCount();
- mysqlPtr->status = MYSQL_STATUS_GET_RESULT;
- drsPtr = stmtPtr->getResultSet();
+ if (stmtPtr->getMoreResults() || stmtPtr->getUpdateCount() != -1)
+ {
+ result = 0;
+ mysqlPtr->affected_rows = stmtPtr->getUpdateCount();
+ mysqlPtr->status = MYSQL_STATUS_GET_RESULT;
+ drsPtr = stmtPtr->getResultSet();
+ }
+
+ reset_error();
+ }
+ catch (CarobException &e)
+ {
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ result = 1;
}
-
- reset_error();
}
- catch (CarobException &e)
+ catch (ConverterException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ set_error(0, e.description().c_str(), error_sqlstate[SQLT_UNKNOWN]);
result = 1;
}
}
@@ -602,16 +635,25 @@

try
{
- connectionPtr->setAutoCommit(mode);
- LOG4CXX_DEBUG(logger, "Leaving set_autocommit: result=1");
-
- reset_error();
-
- return true;
+ try
+ {
+ connectionPtr->setAutoCommit(mode);
+ LOG4CXX_DEBUG(logger, "Leaving set_autocommit: result=1");
+
+ reset_error();
+
+ return true;
+ }
+ catch (CarobException &e)
+ {
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ LOG4CXX_DEBUG(logger, "Leaving set_autocommit: result=0");
+ return 0;
+ }
}
- catch (CarobException &e)
+ catch (ConverterException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ set_error(0, e.description().c_str(), error_sqlstate[SQLT_UNKNOWN]);
LOG4CXX_DEBUG(logger, "Leaving set_autocommit: result=0");
return 0;
}
@@ -631,16 +673,25 @@

try
{
- connectionPtr->commit();
- LOG4CXX_DEBUG(logger, "Leaving commit: result=1");
-
- reset_error();
-
- return true;
+ try
+ {
+ connectionPtr->commit();
+ LOG4CXX_DEBUG(logger, "Leaving commit: result=1");
+
+ reset_error();
+
+ return true;
+ }
+ catch (CarobException &e)
+ {
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ LOG4CXX_DEBUG(logger, "Leaving commit: result=0");
+ return 0;
+ }
}
- catch (CarobException &e)
+ catch (ConverterException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ set_error(0, e.description().c_str(), error_sqlstate[SQLT_UNKNOWN]);
LOG4CXX_DEBUG(logger, "Leaving commit: result=0");
return 0;
}
@@ -660,18 +711,27 @@

try
{
- connectionPtr->rollback();
- LOG4CXX_DEBUG(logger, "Leaving rollback: result=1");
-
- reset_error();
-
- return true;
+ try
+ {
+ connectionPtr->rollback();
+ LOG4CXX_DEBUG(logger, "Leaving rollback: result=1");
+
+ reset_error();
+
+ return true;
+ }
+ catch (CarobException &e)
+ {
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ LOG4CXX_DEBUG(logger, "Leaving rollback: result=0");
+ return false;
+ }
}
- catch (CarobException &e)
+ catch (ConverterException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ set_error(0, e.description().c_str(), error_sqlstate[SQLT_UNKNOWN]);
LOG4CXX_DEBUG(logger, "Leaving rollback: result=0");
- return false;
+ return 0;
}
}

@@ -1102,40 +1162,48 @@
unsigned long
CarobMYSQL::real_escape_string (char *to, const char *from, unsigned long
length)
{
- wstring w = to_wstring(string(from, length));
- std::wstring::const_iterator i = w.begin();
- wstring r;
- wchar_t esc;
-
- for (; i != w.end(); i++)
+ try
{
- esc = 0;
- switch (*i)
- {
- case L'\0':
- case L'\n':
- case L'\r':
- case L'\\':
- case L'\'':
- case L'"': esc = *i; break;
- case L'\032': esc = L'Z'; break;
- }
- if (esc)
- {
- r.push_back(L'\\');
- r.push_back(esc);
- }
- else
+ wstring w = to_wstring(string(from, length));
+ std::wstring::const_iterator i = w.begin();
+ wstring r;
+ wchar_t esc;
+
+ for (; i != w.end(); i++)
{
- r.push_back(*i);
+ esc = 0;
+ switch (*i)
+ {
+ case L'\0':
+ case L'\n':
+ case L'\r':
+ case L'\\':
+ case L'\'':
+ case L'"': esc = *i; break;
+ case L'\032': esc = L'Z'; break;
+ }
+ if (esc)
+ {
+ r.push_back(L'\\');
+ r.push_back(esc);
+ }
+ else
+ {
+ r.push_back(*i);
+ }
}
- }
-
- string s = from_wstring(r);
-
- size_t len = s.length() < 2*length ? s.length() : 2*length-1;
- memcpy(to, s.data(), len);
- to[len] = 0;

- return (s.length() < 2*length) ? (unsigned long) (s.length()) : (unsigned
long) ~0;
+ string s = from_wstring(r);
+
+ size_t len = s.length() < 2*length ? s.length() : 2*length-1;
+ memcpy(to, s.data(), len);
+ to[len] = 0;
+
+ return (s.length() < 2*length) ? (unsigned long) (s.length()) : (unsigned
long) ~0;
+ }
+ catch (ConverterException &e)
+ {
+ set_error(0, e.description().c_str(), error_sqlstate[SQLT_UNKNOWN]);
+ return mysql_escape_string(to, from, length);
+ }
}
Index: libmysequoia/src/CarobStmt.cpp
diff -u libmysequoia/src/CarobStmt.cpp:1.29 libmysequoia/src/CarobStmt.cpp:1.30
--- libmysequoia/src/CarobStmt.cpp:1.29 Wed Mar 15 08:50:46 2006
+++ libmysequoia/src/CarobStmt.cpp Fri Mar 24 14:00:37 2006
@@ -97,34 +97,43 @@
int result = 0;

clear();
-
+
try
- {
- c_stmt =
cmysql->connectionPtr->createParameterStatement(to_wstring(string(query,
length)));
- m_stmt->param_count = c_stmt->getParameterCount();
- m_stmt->state = MYSQL_STMT_PREPARE_DONE;
- m_stmt->params = new MYSQL_BIND[m_stmt->param_count];
-
+ {
try
{
- ResultSetMetaData *rsmdPtr = c_stmt->getMetaData();
- if (rsmdPtr)
+ c_stmt =
cmysql->connectionPtr->createParameterStatement(to_wstring(string(query,
length)));
+ m_stmt->param_count = c_stmt->getParameterCount();
+ m_stmt->state = MYSQL_STMT_PREPARE_DONE;
+ m_stmt->params = new MYSQL_BIND[m_stmt->param_count];
+
+ try
{
- m_stmt->field_count = rsmdPtr->getColumnCount();
- get_query_fields(m_stmt->fields, rsmdPtr);
- m_stmt->bind = new MYSQL_BIND[m_stmt->field_count];
+ ResultSetMetaData *rsmdPtr = c_stmt->getMetaData();
+ if (rsmdPtr)
+ {
+ m_stmt->field_count = rsmdPtr->getColumnCount();
+ get_query_fields(m_stmt->fields, rsmdPtr);
+ m_stmt->bind = new MYSQL_BIND[m_stmt->field_count];
+ }
+ } catch (BackendException &e)
+ {
+ LOG4CXX_DEBUG(logger, "Prepare: errno=" << e.getErrorCode() << "
error=" << from_wstring(e.description()));
}
- } catch (BackendException &e)
+ }
+ catch (CarobException &e)
{
- LOG4CXX_DEBUG(logger, "Prepare: errno=" << e.getErrorCode() << " error="
<< from_wstring(e.description()));
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ result = 1;
}
}
- catch (CarobException &e)
+ catch (ConverterException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ set_error(0, e.description().c_str(), error_sqlstate[SQLT_UNKNOWN]);
result = 1;
}

+
LOG4CXX_DEBUG(logger, "Leaving prepare: result=" << result);

return result;
@@ -276,82 +285,89 @@

try
{
- MYSQL_BIND *p = m_stmt->params;
- for (unsigned int no=1; no <= m_stmt->param_count; no++, p++)
+ try
{
- if (*p->is_null)
- c_stmt->setNull(no);
+ MYSQL_BIND *p = m_stmt->params;
+ for (unsigned int no=1; no <= m_stmt->param_count; no++, p++)
+ {
+ if (*p->is_null)
+ c_stmt->setNull(no);
+ else
+ switch (p->buffer_type)
+ {
+ case MYSQL_TYPE_TINY:
+ c_stmt->setByte(no, *(java_byte *)p->buffer);
+ break;
+ case MYSQL_TYPE_SHORT:
+ c_stmt->setShort(no, *(short *)p->buffer);
+ break;
+ case MYSQL_TYPE_LONG:
+ c_stmt->setInt(no, *(int *)p->buffer);
+ break;
+ case MYSQL_TYPE_LONGLONG:
+ c_stmt->setLong(no, *(int64_t *)p->buffer);
+ break;
+ case MYSQL_TYPE_FLOAT:
+ c_stmt->setFloat(no, *(float *)p->buffer);
+ break;
+ case MYSQL_TYPE_DOUBLE:
+ c_stmt->setDouble(no, *(double *)p->buffer);
+ break;
+ case MYSQL_TYPE_TINY_BLOB:
+ case MYSQL_TYPE_MEDIUM_BLOB:
+ case MYSQL_TYPE_LONG_BLOB:
+ case MYSQL_TYPE_BLOB:
+ if (p->long_data_used && LONGDATAFIELD(p))
+ {
+ string *s = (string *)LONGDATAFIELD(p);
+ c_stmt->setBlob(no, s->data(), s->size());
+ }
+ else
+ c_stmt->setBlob(no, p->buffer, p->buffer_length);
+ break;
+ case MYSQL_TYPE_DECIMAL:
+ #ifdef MYSQL5
+ case MYSQL_TYPE_NEWDECIMAL:
+ case MYSQL_TYPE_VARCHAR:
+ #endif
+ case MYSQL_TYPE_VAR_STRING:
+ case MYSQL_TYPE_STRING:
+ if (p->long_data_used && LONGDATAFIELD(p))
+ c_stmt->setString(no, to_wstring(*(string
*)LONGDATAFIELD(p)));
+ else
+ c_stmt->setString(no, to_wstring(string((char *)p->buffer,
p->buffer_length)));
+ break;
+ case MYSQL_TYPE_TIME:
+ case MYSQL_TYPE_DATE:
+ case MYSQL_TYPE_DATETIME:
+ case MYSQL_TYPE_TIMESTAMP:
+ char buffer[20];
+ MYSQL_TIME_to_str((MYSQL_TIME *)p->buffer, buffer,
sizeof(buffer));
+ c_stmt->setString(no,
to_wstring(string(buffer,strlen(buffer))));
+ break;
+ case MYSQL_TYPE_NULL:
+ break;
+ default:
+ LOG4CXX_FATAL(logger, "This should never happen!!");
+ /* TODO support other types */
+ }
+ }
+ if (!c_stmt->execute())
+ m_stmt->affected_rows = c_stmt->getUpdateCount();
else
- switch (p->buffer_type)
- {
- case MYSQL_TYPE_TINY:
- c_stmt->setByte(no, *(java_byte *)p->buffer);
- break;
- case MYSQL_TYPE_SHORT:
- c_stmt->setShort(no, *(short *)p->buffer);
- break;
- case MYSQL_TYPE_LONG:
- c_stmt->setInt(no, *(int *)p->buffer);
- break;
- case MYSQL_TYPE_LONGLONG:
- c_stmt->setLong(no, *(int64_t *)p->buffer);
- break;
- case MYSQL_TYPE_FLOAT:
- c_stmt->setFloat(no, *(float *)p->buffer);
- break;
- case MYSQL_TYPE_DOUBLE:
- c_stmt->setDouble(no, *(double *)p->buffer);
- break;
- case MYSQL_TYPE_TINY_BLOB:
- case MYSQL_TYPE_MEDIUM_BLOB:
- case MYSQL_TYPE_LONG_BLOB:
- case MYSQL_TYPE_BLOB:
- if (p->long_data_used && LONGDATAFIELD(p))
- {
- string *s = (string *)LONGDATAFIELD(p);
- c_stmt->setBlob(no, s->data(), s->size());
- }
- else
- c_stmt->setBlob(no, p->buffer, p->buffer_length);
- break;
- case MYSQL_TYPE_DECIMAL:
-#ifdef MYSQL5
- case MYSQL_TYPE_NEWDECIMAL:
- case MYSQL_TYPE_VARCHAR:
-#endif
- case MYSQL_TYPE_VAR_STRING:
- case MYSQL_TYPE_STRING:
- if (p->long_data_used && LONGDATAFIELD(p))
- c_stmt->setString(no, to_wstring(*(string
*)LONGDATAFIELD(p)));
- else
- c_stmt->setString(no, to_wstring(string((char *)p->buffer,
p->buffer_length)));
- break;
- case MYSQL_TYPE_TIME:
- case MYSQL_TYPE_DATE:
- case MYSQL_TYPE_DATETIME:
- case MYSQL_TYPE_TIMESTAMP:
- char buffer[20];
- MYSQL_TIME_to_str((MYSQL_TIME *)p->buffer, buffer,
sizeof(buffer));
- c_stmt->setString(no,
to_wstring(string(buffer,strlen(buffer))));
- break;
- case MYSQL_TYPE_NULL:
- break;
- default:
- LOG4CXX_FATAL(logger, "This should never happen!!");
- /* TODO support other types */
- }
+ liveResultSet = c_stmt->getResultSet();
+
+ m_stmt->state = MYSQL_STMT_EXECUTE_DONE;
+ result = 0;
+ }
+ catch (CarobException &e)
+ {
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
}
- if (!c_stmt->execute())
- m_stmt->affected_rows = c_stmt->getUpdateCount();
- else
- liveResultSet = c_stmt->getResultSet();
-
- m_stmt->state = MYSQL_STMT_EXECUTE_DONE;
- result = 0;
}
- catch (CarobException &e)
+ catch (ConverterException &e)
{
- set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ set_error(0, e.description().c_str(), error_sqlstate[SQLT_UNKNOWN]);
}
}

@@ -463,6 +479,7 @@
result = 1;
}
else
+ try
{
//check if there are more results to fetch
if (m_stmt->result.data ? m_stmt->data_cursor != 0 : liveResultSet->next())
@@ -496,6 +513,11 @@
else
result = MYSQL_NO_DATA;
}
+ catch (ConverterException &e)
+ {
+ set_error(0, e.description().c_str(), error_sqlstate[SQLT_UNKNOWN]);
+ result = 1;
+ }

LOG4CXX_DEBUG(logger, "Leaving fetch: result=" << result);
return result;
@@ -516,6 +538,7 @@
if (!bind)
set_error(CR_NULL_POINTER, SQLT_UNKNOWN);
else
+ try
{
link_bind(bind);
bind->offset = offset;
@@ -524,6 +547,10 @@

result = 0;
}
+ catch (ConverterException &e)
+ {
+ set_error(0, e.description().c_str(), error_sqlstate[SQLT_UNKNOWN]);
+ }

LOG4CXX_DEBUG(logger, "Leaving fetch_column: result=" << result);
return result;
@@ -600,40 +627,56 @@
result = 1;
}
else
- if (m_stmt->field_count && liveResultSet)
- {
- if (m_stmt->result.data)
- free_catched_result(m_stmt);
-
- memset(&m_stmt->result, 0, sizeof(MYSQL_DATA));
- m_stmt->result.fields = m_stmt->field_count;
+ try
+ {
+ try
+ {
+ if (m_stmt->field_count && liveResultSet)
+ {
+ if (m_stmt->result.data)
+ free_catched_result(m_stmt);

- MYSQL_ROWS *prev = 0;
- //Fetch row by row and allocate memory for each row
- while (liveResultSet->next())
- {
- MYSQL_ROWS *row = new MYSQL_ROWS;
- memset(row,0,sizeof(MYSQL_ROWS));
- row->data = new PCHAR[m_stmt->field_count];
-
- MYSQL_FIELD *fPtr = m_stmt->fields;
- MYSQL_ROW dataPtr = row->data;
-
- for (unsigned colNo=1; colNo <= m_stmt->field_count; colNo++, fPtr++,
dataPtr++)
- *dataPtr = (char *)alloc_fetch_field(fPtr, colNo);
- if (prev)
- prev->next = row;
- else
- m_stmt->result.data = row;
- prev = row;
- m_stmt->result.rows++;
+ memset(&m_stmt->result, 0, sizeof(MYSQL_DATA));
+ m_stmt->result.fields = m_stmt->field_count;
+
+ MYSQL_ROWS *prev = 0;
+ //Fetch row by row and allocate memory for each row
+ while (liveResultSet->next())
+ {
+ MYSQL_ROWS *row = new MYSQL_ROWS;
+ memset(row,0,sizeof(MYSQL_ROWS));
+ row->data = new PCHAR[m_stmt->field_count];
+
+ MYSQL_FIELD *fPtr = m_stmt->fields;
+ MYSQL_ROW dataPtr = row->data;
+
+ for (unsigned colNo=1; colNo <= m_stmt->field_count; colNo++,
fPtr++, dataPtr++)
+ *dataPtr = (char *)alloc_fetch_field(fPtr, colNo);
+ if (prev)
+ prev->next = row;
+ else
+ m_stmt->result.data = row;
+ prev = row;
+ m_stmt->result.rows++;
+ }
+ m_stmt->data_cursor = m_stmt->result.data;
+ m_stmt->affected_rows = m_stmt->result.rows;
+
+ //Release the Carob dataset
+ c_stmt->close();
+ liveResultSet = 0;
+ }
}
- m_stmt->data_cursor = m_stmt->result.data;
- m_stmt->affected_rows = m_stmt->result.rows;
-
- //Release the Carob dataset
- c_stmt->close();
- liveResultSet = 0;
+ catch (CarobException &e)
+ {
+ set_error(e.getErrorCode(), from_wstring(e.description()).c_str(),
from_wstring(e.getSQLState()).c_str());
+ result = 1;
+ }
+ }
+ catch (ConverterException &e)
+ {
+ set_error(0, e.description().c_str(), error_sqlstate[SQLT_UNKNOWN]);
+ result = 1;
}

LOG4CXX_DEBUG(logger, "Leaving store_result: result=" << result);


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation

Home | advertise | OSDir is an inevitable website. super tiny logo