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
51class TMySQLServer : public TSQLServer {
52
53protected:
54 MYSQL *fMySQL; // connection to MySQL server
55 TString fInfo; // server info string
56
57public:
58 TMySQLServer(const char *db, const char *uid, const char *pw);
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);
73 Int_t CreateDataBase(const char *dbname);
74 Int_t DropDataBase(const char *dbname);
75 Int_t Reload();
77 const char *ServerInfo();
78
80 Bool_t Commit();
82
84 Int_t Ping();
85
86 ClassDef(TMySQLServer,0) // Connection to MySQL server
87};
88
89#endif
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const char Option_t
Definition: RtypesCore.h:62
#define ClassDef(name, id)
Definition: Rtypes.h:326
A doubly linked list.
Definition: TList.h:44
Int_t Shutdown()
Shutdown the database server.
TSQLResult * Query(const char *sql)
Execute SQL command.
Int_t SelectDataBase(const char *dbname)
Select a database. Returns 0 if successful, non-zero otherwise.
Int_t GetMaxIdentifierLength()
Definition: TMySQLServer.h:72
void Close(Option_t *opt="")
Close connection to MySQL DB server.
Bool_t PingVerify()
Execute Ping to SQL Connection.
TSQLTableInfo * GetTableInfo(const char *tablename)
Produces SQL table info.
TMySQLServer(const char *db, const char *uid, const char *pw)
Open a connection to a MySQL DB server.
TString fInfo
Definition: TMySQLServer.h:55
TList * GetTablesList(const char *wild=0)
Return list of tables with specified wildcard.
Bool_t Rollback()
Rollback changes.
Int_t DropDataBase(const char *dbname)
Drop (i.e.
Int_t Ping()
Execute Ping to SQL Connection using the mysql_ping function.
const char * ServerInfo()
Return server info in form "MySQL <vesrion>".
Bool_t Exec(const char *sql)
Execute SQL command which does not produce any result sets.
Int_t Reload()
Reload permission tables.
TSQLResult * GetColumns(const char *dbname, const char *table, const char *wild=0)
List all columns in specified table in the specified database.
Int_t CreateDataBase(const char *dbname)
Create a database. Returns 0 if successful, non-zero otherwise.
Bool_t Commit()
Commit changes.
Bool_t HasStatement() const
Return kTRUE if TSQLStatement class is supported.
~TMySQLServer()
Close connection to MySQL DB server.
MYSQL * fMySQL
Definition: TMySQLServer.h:54
Bool_t StartTransaction()
Start transaction.
TSQLResult * GetTables(const char *dbname, const char *wild=0)
List all tables in the specified database.
TSQLResult * GetDataBases(const char *wild=0)
List all available databases.
TSQLStatement * Statement(const char *sql, Int_t=100)
Produce TMySQLStatement.
Basic string class.
Definition: TString.h:131