Logo ROOT  
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 #include "TSQLServer.h"
48 
49 #include <mysql.h>
50 
51 class TMySQLServer : public TSQLServer {
52 
53 protected:
54  MYSQL *fMySQL{nullptr}; // 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="") final;
62  TSQLResult *Query(const char *sql) final;
63  Bool_t Exec(const char* sql) final;
64  TSQLStatement *Statement(const char *sql, Int_t = 100) final;
65  Bool_t HasStatement() const final;
66  Int_t SelectDataBase(const char *dbname) final;
67  TSQLResult *GetDataBases(const char *wild = nullptr) final;
68  TSQLResult *GetTables(const char *dbname, const char *wild = nullptr) final;
69  TList *GetTablesList(const char* wild = nullptr) final;
70  TSQLTableInfo *GetTableInfo(const char* tablename) final;
71  TSQLResult *GetColumns(const char *dbname, const char *table, const char *wild = nullptr) final;
72  Int_t GetMaxIdentifierLength() final { return 64; }
73  Int_t CreateDataBase(const char *dbname) final;
74  Int_t DropDataBase(const char *dbname) final;
75  Int_t Reload() final;
76  Int_t Shutdown() final;
77  const char *ServerInfo() final;
78 
79  Bool_t StartTransaction() final;
80  Bool_t Commit() final;
81  Bool_t Rollback() final;
82 
83  Bool_t PingVerify() final;
84  Int_t Ping() final;
85 
86  ClassDefOverride(TMySQLServer,0) // Connection to MySQL server
87 };
88 
89 #endif
TMySQLServer::HasStatement
Bool_t HasStatement() const final
Return kTRUE if TSQLStatement class is supported.
Definition: TMySQLServer.cxx:692
Option_t
const char Option_t
Definition: RtypesCore.h:66
TMySQLServer::TMySQLServer
TMySQLServer(const char *db, const char *uid, const char *pw)
Open a connection to a MySQL DB server.
Definition: TMySQLServer.cxx:83
TMySQLServer::Reload
Int_t Reload() final
Reload permission tables.
Definition: TMySQLServer.cxx:638
TMySQLServer::fInfo
TString fInfo
Definition: TMySQLServer.h:55
TSQLServer.h
TMySQLServer::~TMySQLServer
~TMySQLServer()
Close connection to MySQL DB server.
Definition: TMySQLServer.cxx:226
Int_t
int Int_t
Definition: RtypesCore.h:45
TMySQLServer::Shutdown
Int_t Shutdown() final
Shutdown the database server.
Definition: TMySQLServer.cxx:653
TSQLTableInfo
Definition: TSQLTableInfo.h:20
TMySQLServer::Query
TSQLResult * Query(const char *sql) final
Execute SQL command.
Definition: TMySQLServer.cxx:276
TMySQLServer::PingVerify
Bool_t PingVerify() final
Execute Ping to SQL Connection.
Definition: TMySQLServer.cxx:795
TMySQLServer::StartTransaction
Bool_t StartTransaction() final
Start transaction.
Definition: TMySQLServer.cxx:738
TString
Basic string class.
Definition: TString.h:136
ClassDefOverride
#define ClassDefOverride(name, id)
Definition: Rtypes.h:329
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TMySQLServer::CreateDataBase
Int_t CreateDataBase(const char *dbname) final
Create a database. Returns 0 if successful, non-zero otherwise.
Definition: TMySQLServer.cxx:608
bool
TMySQLServer::GetDataBases
TSQLResult * GetDataBases(const char *wild=nullptr) final
List all available databases.
Definition: TMySQLServer.cxx:323
TSQLResult
Definition: TSQLResult.h:32
TMySQLServer::GetTables
TSQLResult * GetTables(const char *dbname, const char *wild=nullptr) final
List all tables in the specified database.
Definition: TMySQLServer.cxx:340
TMySQLServer::ServerInfo
const char * ServerInfo() final
Return server info in form "MySQL <vesrion>".
Definition: TMySQLServer.cxx:674
TMySQLServer::Statement
TSQLStatement * Statement(const char *sql, Int_t=100) final
Produce TMySQLStatement.
Definition: TMySQLServer.cxx:705
TMySQLServer::GetTableInfo
TSQLTableInfo * GetTableInfo(const char *tablename) final
Produces SQL table info.
Definition: TMySQLServer.cxx:394
TMySQLServer::fMySQL
MYSQL * fMySQL
Definition: TMySQLServer.h:54
TMySQLServer::Close
void Close(Option_t *opt="") final
Close connection to MySQL DB server.
Definition: TMySQLServer.cxx:260
TMySQLServer
Definition: TMySQLServer.h:51
TMySQLServer::Commit
Bool_t Commit() final
Commit changes.
Definition: TMySQLServer.cxx:748
TSQLStatement
Definition: TSQLStatement.h:21
TMySQLServer::GetMaxIdentifierLength
Int_t GetMaxIdentifierLength() final
Definition: TMySQLServer.h:72
TMySQLServer::Ping
Int_t Ping() final
Execute Ping to SQL Connection using the mysql_ping function.
Definition: TMySQLServer.cxx:814
TMySQLServer::SelectDataBase
Int_t SelectDataBase(const char *dbname) final
Select a database. Returns 0 if successful, non-zero otherwise.
Definition: TMySQLServer.cxx:306
TMySQLServer::DropDataBase
Int_t DropDataBase(const char *dbname) final
Drop (i.e.
Definition: TMySQLServer.cxx:623
TMySQLServer::Exec
Bool_t Exec(const char *sql) final
Execute SQL command which does not produce any result sets.
Definition: TMySQLServer.cxx:293
TMySQLServer::GetColumns
TSQLResult * GetColumns(const char *dbname, const char *table, const char *wild=nullptr) final
List all columns in specified table in the specified database.
Definition: TMySQLServer.cxx:589
TMySQLServer::GetTablesList
TList * GetTablesList(const char *wild=nullptr) final
Return list of tables with specified wildcard.
Definition: TMySQLServer.cxx:357
TSQLServer
Definition: TSQLServer.h:41
TMySQLServer::Rollback
Bool_t Rollback() final
Rollback changes.
Definition: TMySQLServer.cxx:770
TList
A doubly linked list.
Definition: TList.h:44
int