00001 // @(#)root/mysql:$Id: TMySQLServer.h 29976 2009-08-31 13:34:53Z rdm $ 00002 // Author: Fons Rademakers 15/02/2000 00003 00004 /************************************************************************* 00005 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * 00006 * All rights reserved. * 00007 * * 00008 * For the licensing terms see $ROOTSYS/LICENSE. * 00009 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00010 *************************************************************************/ 00011 00012 #ifndef ROOT_TMySQLServer 00013 #define ROOT_TMySQLServer 00014 00015 ////////////////////////////////////////////////////////////////////////// 00016 // // 00017 // TMySQLServer // 00018 // // 00019 // MySQL server plugin implementing the TSQLServer interface. // 00020 // // 00021 // To open a connection to a server use the static method Connect(). // 00022 // The db argument of Connect() is of the form: // 00023 // mysql://<host>[:<port>][/<database>], e.g. // 00024 // mysql://pcroot.cern.ch:3456/test // 00025 // // 00026 // As an example of connecting to mysql we assume that the server is // 00027 // running on the local host and that you have access to a database // 00028 // named "test" by connecting using an account that has a username and // 00029 // password of "tuser" and "tpass". You can set up this account // 00030 // by using the "mysql" program to connect to the server as the MySQL // 00031 // root user and issuing the following statement: // 00032 // // 00033 // mysql> GRANT ALL ON test.* TO 'tuser'@'localhost' IDENTIFIED BY 'tpass'; 00034 // // 00035 // If the test database does not exist, create it with this statement: // 00036 // // 00037 // mysql> CREATE DATABASE test; // 00038 // // 00039 // If you want to use a different server host, username, password, // 00040 // or database name, just substitute the appropriate values. // 00041 // To connect do: // 00042 // // 00043 // TSQLServer *db = TSQLServer::Connect("mysql://localhost/test", "tuser", "tpass"); 00044 // // 00045 ////////////////////////////////////////////////////////////////////////// 00046 00047 #ifndef ROOT_TSQLServer 00048 #include "TSQLServer.h" 00049 #endif 00050 00051 #if !defined(__CINT__) 00052 #ifdef R__WIN32 00053 #include <winsock2.h> 00054 #else 00055 #include <sys/time.h> 00056 #endif 00057 #include <mysql.h> 00058 #else 00059 struct MYSQL; 00060 #endif 00061 00062 00063 00064 class TMySQLServer : public TSQLServer { 00065 00066 protected: 00067 MYSQL *fMySQL; // connection to MySQL server 00068 TString fInfo; // server info string 00069 00070 public: 00071 TMySQLServer(const char *db, const char *uid, const char *pw); 00072 ~TMySQLServer(); 00073 00074 void Close(Option_t *opt=""); 00075 TSQLResult *Query(const char *sql); 00076 Bool_t Exec(const char* sql); 00077 TSQLStatement *Statement(const char *sql, Int_t = 100); 00078 Bool_t HasStatement() const; 00079 Int_t SelectDataBase(const char *dbname); 00080 TSQLResult *GetDataBases(const char *wild = 0); 00081 TSQLResult *GetTables(const char *dbname, const char *wild = 0); 00082 TList *GetTablesList(const char* wild = 0); 00083 TSQLTableInfo *GetTableInfo(const char* tablename); 00084 TSQLResult *GetColumns(const char *dbname, const char *table, const char *wild = 0); 00085 Int_t GetMaxIdentifierLength() { return 64; } 00086 Int_t CreateDataBase(const char *dbname); 00087 Int_t DropDataBase(const char *dbname); 00088 Int_t Reload(); 00089 Int_t Shutdown(); 00090 const char *ServerInfo(); 00091 00092 Bool_t StartTransaction(); 00093 Bool_t Commit(); 00094 Bool_t Rollback(); 00095 00096 Bool_t PingVerify(); 00097 Int_t Ping(); 00098 00099 ClassDef(TMySQLServer,0) // Connection to MySQL server 00100 }; 00101 00102 #endif