Date: Friday, December 2, 2005 @ 13:58:39
Author: csaba
Path: /cvsroot/carob/libmysequoia/include
Added: CarobMySQL.hpp (1.1)
- added the missing include directory
----------------+
CarobMySQL.hpp | 196 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 196 insertions(+)
Index: libmysequoia/include/CarobMySQL.hpp
diff -u /dev/null libmysequoia/include/CarobMySQL.hpp:1.1
--- /dev/null Fri Dec 2 13:58:39 2005
+++ libmysequoia/include/CarobMySQL.hpp Fri Dec 2 13:58:39 2005
@@ -0,0 +1,196 @@
+/**
+ * Sequoia: Database clustering technology.
+ * Copyright (C) 2005 Emic Networks
+ * Contact: [EMAIL PROTECTED]
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Initial developer(s): Zsolt Simon, Csaba Simon
+ * Contributor(s):
+ */
+
+#ifndef _CAROBMYSQL_HPP
+#define _CAROBMYSQL_HPP
+
+/* MySQL includes */
+#include <mysql.h>
+
+/* Carob includes */
+#include <ConnectionParameters.hpp>
+#include <ConnectionPool.hpp>
+#include <DriverResultSet.hpp>
+#include <Statement.hpp>
+
+using namespace CarobNS;
+
+class CarobMYSQL;
+
+typedef struct st_cmysql {
+ MYSQL my;
+ CarobMYSQL *carob;
+} CMYSQL;
+
+class CarobMYSQL
+{
+public:
+ CarobMYSQL();
+ ~CarobMYSQL();
+
+ /**
+ * Connect to sequoia through Carob. Initialize the corresponding fields
in the
+ * MYSQL structure (eg. host, user, passwd, db, port, ...)
+ * If db is null a connection will be a lazy connect which means when we
specify
+ * the database name with select_db the real connect will happen. This is
needed
+ * because sequoia does not support a connect without a virtual database
name.
+ * @param host name of the host to connect
+ * @param port number of the port, if 0 use the default 25322
+ * @param unix_socket if this parameter is not null, return an error
+ * @param clientflag connection specific flags
+ * @return if the connection was successful return true otherwise false
+ * and set the corresponding mysql error
+ */
+ bool connect(const char *host, const char *user,
+ const char *passwd, const char *db, unsigned int port,
+ const char *unix_socket, unsigned long clientflag);
+
+ /**
+ * Modify the virtual database. If a lazy connection is ongoing then
+ * try to connect to the database
+ * @param db name of the virtual database
+ * @return if the connection was successful return true otherwise false
+ * and set the corresponding mysql error
+ */
+ bool select_db(const char *db);
+
+ /**
+ * Change the user or database. A default rollback will happen even if the
+ * user is the same. If the new user can't connect to the server, the
current
+ * user will remain. If a lazy connection is ongoing then try to connect to
+ * the database
+ * @param user name of the user which is used in connection
+ * @param passwd password of the user used in connect
+ * @param db name of the virtual database
+ * @return if the connection was successful return true otherwise false
+ * and set the corresponding mysql error
+ */
+ bool change_user(const char *user, const char *passwd, const char *db);
+
+ /**
+ * Executes a query on the server. If a lazy connection is ongoing
+ * returns an error. If a query was n
+ * @param query the sql query to be executed, can contain null characters
+ * @param length the length of the query parameter
+ * @return true if the query was executed otherwise false and set the
+ * corresponding mysql error
+ */
+ bool real_query(const char *query, ulong length);
+
+ /**
+ * Gets the result of the query in MYSQL_RES format, and set the
correspondent
+ * MYSQL fields. If fetch_all is specified it will fetch all rows from the
+ * server and close the query on the server, otherwise will fetch
+ * only 1 row and will leave open the query cursor on the server.
+ * In this case at a new fetch row network operation will happen.
+ * Only one live query / connection can exists.
+ * @param fetch_all true if all results are storred in the memory
+ * @return NULL if the query was execute only type (eq INSERT ...) or an
error
+ * occured, in this case sets the corresponding mysql
error
+ * if fetch_all was true will return a pointer to the newly
allocated
+ * results. The results must be fread after use with
free_results
+ * if fetch_all was false will return liveResultPtr
+ */
+ MYSQL_RES * get_results(my_bool fetch_all);
+
+ /**
+ * In the case of multiple statement execution, returns true if
+ * there are more results on the server
+ */
+ bool more_results();
+
+ /**
+ * In the case of multiple statement execution, fetch the next result
from the
+ * server
+ * @return true if the operation was successful
+ */
+ bool next_result();
+
+ /**
+ * Free the stored results
+ * If res == liveResultPtr will close the query on the server
+ */
+ void free_results(MYSQL_RES *res);
+
+ /**
+ * Return true if there are no more rows to fetch from the result set or
+ * there is no result set
+ */
+ bool eof();
+
+ /**
+ * Set the autocommit mode. If autocommit is on then all SQL statements
will
+ * be executed and commited as individual transactions.
+ * @param mode - true set autocommit on
+ * false set autocommit off
+ * @return true on success otherwise false
+ */
+ bool set_autocommit(const my_bool mode);
+
+ /**
+ * Make all changes permanent since the previous commit/rollback
+ * @return true on success otherwise false
+ */
+ bool commit();
+
+ /**
+ * Rollback all changes since the previous commit
+ * @return true on succes otherwise false
+ */
+ bool rollback();
+
+ /**
+ * List a table fields
+ * @param wild a regular expression mathing the field names
+ * @param table name of the table
+ * @return a MYSQL_RES with the name of the fields
+ */
+ MYSQL_RES *list_table_fields(const char *table, const char *wild);
+
+ /**
+ * List the databases names
+ * @param wild a regular expression matching the databases names
+ * @return MYSQL_RES with the name of the databases
+ */
+ MYSQL_RES *list_databases(const char *wild);
+
+ /**
+ * List the table names in the current database
+ * @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);
+
+ /**
+ * Returns a pointer to the MYSQL structure
+ */
+ MYSQL *getMYSQL();
+
+private:
+ CMYSQL *mysqlPtr;
+ Connection *connectionPtr;
+ ConnectionPool *connectionPool;
+ Statement *stmtPtr;
+ //holds the result set for 'live' type of results
+ MYSQL_RES *liveResultPtr;
+};
+
+#endif /* _CAROBMYSQL_HPP */
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits