ROOT  6.06/09
Reference Guide
TMySQLServer.h
Go to the documentation of this file.
1 // @(#)root/mysql:$Id$
2 // Author: Fons Rademakers 15/02/2000
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TMySQLServer
13 #define ROOT_TMySQLServer
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TMySQLServer //
18 // //
19 // MySQL server plugin implementing the TSQLServer interface. //
20 // //
21 // To open a connection to a server use the static method Connect(). //
22 // The db argument of Connect() is of the form: //
23 // mysql://<host>[:<port>][/<database>], e.g. //
24 // mysql://pcroot.cern.ch:3456/test //
25 // //
26 // As an example of connecting to mysql we assume that the server is //
27 // running on the local host and that you have access to a database //
28 // named "test" by connecting using an account that has a username and //
29 // password of "tuser" and "tpass". You can set up this account //
30 // by using the "mysql" program to connect to the server as the MySQL //
31 // root user and issuing the following statement: //
32 // //
33 // mysql> GRANT ALL ON test.* TO 'tuser'@'localhost' IDENTIFIED BY 'tpass';
34 // //
35 // If the test database does not exist, create it with this statement: //
36 // //
37 // mysql> CREATE DATABASE test; //
38 // //
39 // If you want to use a different server host, username, password, //
40 // or database name, just substitute the appropriate values. //
41 // To connect do: //
42 // //
43 // TSQLServer *db = TSQLServer::Connect("mysql://localhost/test", "tuser", "tpass");
44 // //
45 //////////////////////////////////////////////////////////////////////////
46 
47 #ifndef ROOT_TSQLServer
48 #include "TSQLServer.h"
49 #endif
50 
51 #include <mysql.h>
52 
53 class TMySQLServer : public TSQLServer {
54 
55 protected:
56  MYSQL *fMySQL; // connection to MySQL server
57  TString fInfo; // server info string
58 
59 public:
60  TMySQLServer(const char *db, const char *uid, const char *pw);
61  ~TMySQLServer();
62 
63  void Close(Option_t *opt="");
64  TSQLResult *Query(const char *sql);
65  Bool_t Exec(const char* sql);
66  TSQLStatement *Statement(const char *sql, Int_t = 100);
67  Bool_t HasStatement() const;
68  Int_t SelectDataBase(const char *dbname);
69  TSQLResult *GetDataBases(const char *wild = 0);
70  TSQLResult *GetTables(const char *dbname, const char *wild = 0);
71  TList *GetTablesList(const char* wild = 0);
72  TSQLTableInfo *GetTableInfo(const char* tablename);
73  TSQLResult *GetColumns(const char *dbname, const char *table, const char *wild = 0);
74  Int_t GetMaxIdentifierLength() { return 64; }
75  Int_t CreateDataBase(const char *dbname);
76  Int_t DropDataBase(const char *dbname);
77  Int_t Reload();
78  Int_t Shutdown();
79  const char *ServerInfo();
80 
82  Bool_t Commit();
83  Bool_t Rollback();
84 
86  Int_t Ping();
87 
88  ClassDef(TMySQLServer,0) // Connection to MySQL server
89 };
90 
91 #endif
const char * ServerInfo()
Return server info in form "MySQL ".
TMySQLServer(const char *db, const char *uid, const char *pw)
const char Option_t
Definition: RtypesCore.h:62
~TMySQLServer()
Close connection to MySQL DB server.
Bool_t Exec(const char *sql)
Execute SQL command which does not produce any result sets.
TSQLResult * GetDataBases(const char *wild=0)
List all available databases.
Int_t Shutdown()
Shutdown the database server.
Basic string class.
Definition: TString.h:137
void Close(Option_t *opt="")
Close connection to MySQL DB server.
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TSQLStatement * Statement(const char *sql, Int_t=100)
Produce TMySQLStatement.
TSQLResult * Query(const char *sql)
Execute SQL command.
#define ClassDef(name, id)
Definition: Rtypes.h:254
Int_t SelectDataBase(const char *dbname)
Select a database. Returns 0 if successful, non-zero otherwise.
Bool_t StartTransaction()
Start transaction.
TSQLResult * GetColumns(const char *dbname, const char *table, const char *wild=0)
List all columns in specified table in the specified database.
A doubly linked list.
Definition: TList.h:47
TList * GetTablesList(const char *wild=0)
Return list of tables with specified wildcard.
Int_t DropDataBase(const char *dbname)
Drop (i.e.
Int_t Ping()
Execute Ping to SQL Connection using the mysql_ping function.
Bool_t Commit()
Commit changes.
Int_t CreateDataBase(const char *dbname)
Create a database. Returns 0 if successful, non-zero otherwise.
TSQLResult * GetTables(const char *dbname, const char *wild=0)
List all tables in the specified database.
Int_t GetMaxIdentifierLength()
Definition: TMySQLServer.h:74
TString fInfo
Definition: TMySQLServer.h:57
Bool_t PingVerify()
Execute Ping to SQL Connection.
Bool_t HasStatement() const
Return kTRUE if TSQLStatement class is supported.
MYSQL * fMySQL
Definition: TMySQLServer.h:56
Bool_t Rollback()
Rollback changes.
TSQLTableInfo * GetTableInfo(const char *tablename)
Produces SQL table info.
Int_t Reload()
Reload permission tables.