Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 #include "TSQLServer.h"
48 
49 #include <mysql.h>
50 
51 class TMySQLServer : public TSQLServer {
52 
53 protected:
54  MYSQL *fMySQL; // connection to MySQL server
55  TString fInfo; // server info string
56 
57 public:
58  TMySQLServer(const char *db, const char *uid, const char *pw);
59  ~TMySQLServer();
60 
61  void Close(Option_t *opt="");
62  TSQLResult *Query(const char *sql);
63  Bool_t Exec(const char* sql);
64  TSQLStatement *Statement(const char *sql, Int_t = 100);
65  Bool_t HasStatement() const;
66  Int_t SelectDataBase(const char *dbname);
67  TSQLResult *GetDataBases(const char *wild = 0);
68  TSQLResult *GetTables(const char *dbname, const char *wild = 0);
69  TList *GetTablesList(const char* wild = 0);
70  TSQLTableInfo *GetTableInfo(const char* tablename);
71  TSQLResult *GetColumns(const char *dbname, const char *table, const char *wild = 0);
72  Int_t GetMaxIdentifierLength() { return 64; }
73  Int_t CreateDataBase(const char *dbname);
74  Int_t DropDataBase(const char *dbname);
75  Int_t Reload();
76  Int_t Shutdown();
77  const char *ServerInfo();
78 
79  Bool_t StartTransaction();
80  Bool_t Commit();
81  Bool_t Rollback();
82 
83  Bool_t PingVerify();
84  Int_t Ping();
85 
86  ClassDef(TMySQLServer,0) // Connection to MySQL server
87 };
88 
89 #endif