Logo ROOT  
Reference Guide
Go to the documentation of this file.
1// @(#)root/mysql:$Id$
2// Author: Fons Rademakers 15/02/2000
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 *************************************************************************/
12#ifndef ROOT_TMySQLServer
13#define ROOT_TMySQLServer
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// //
47#include "TSQLServer.h"
49#include <mysql.h>
51class TMySQLServer : public TSQLServer {
54 MYSQL *fMySQL{nullptr}; // connection to MySQL server
55 TString fInfo; // server info string
58 TMySQLServer(const char *db, const char *uid, const char *pw);
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;
80 Bool_t Commit() final;
81 Bool_t Rollback() final;
83 Bool_t PingVerify() final;
84 Int_t Ping() final;
86 ClassDefOverride(TMySQLServer,0) // Connection to MySQL server
int Int_t
Definition: CPyCppyy.h:43
bool Bool_t
Definition: RtypesCore.h:63
const char Option_t
Definition: RtypesCore.h:66
#define ClassDefOverride(name, id)
Definition: Rtypes.h:329
A doubly linked list.
Definition: TList.h:44
Int_t SelectDataBase(const char *dbname) final
Select a database. Returns 0 if successful, non-zero otherwise.
Bool_t Rollback() final
Rollback changes.
TSQLResult * GetColumns(const char *dbname, const char *table, const char *wild=nullptr) final
List all columns in specified table in the specified database.
TSQLResult * GetDataBases(const char *wild=nullptr) final
List all available databases.
TSQLStatement * Statement(const char *sql, Int_t=100) final
Produce TMySQLStatement.
void Close(Option_t *opt="") final
Close connection to MySQL DB server.
Bool_t PingVerify() final
Execute Ping to SQL Connection.
TSQLResult * GetTables(const char *dbname, const char *wild=nullptr) final
List all tables in the specified database.
Bool_t StartTransaction() final
Start transaction.
Int_t Reload() final
Reload permission tables.
TMySQLServer(const char *db, const char *uid, const char *pw)
Open a connection to a MySQL DB server.
Int_t GetMaxIdentifierLength() final
Definition: TMySQLServer.h:72
TString fInfo
Definition: TMySQLServer.h:55
TList * GetTablesList(const char *wild=nullptr) final
Return list of tables with specified wildcard.
const char * ServerInfo() final
Return server info in form "MySQL <vesrion>".
TSQLTableInfo * GetTableInfo(const char *tablename) final
Produces SQL table info.
TSQLResult * Query(const char *sql) final
Execute SQL command.
Bool_t Exec(const char *sql) final
Execute SQL command which does not produce any result sets.
Int_t CreateDataBase(const char *dbname) final
Create a database. Returns 0 if successful, non-zero otherwise.
Bool_t HasStatement() const final
Return kTRUE if TSQLStatement class is supported.
Close connection to MySQL DB server.
Definition: TMySQLServer.h:54
Bool_t Commit() final
Commit changes.
Int_t Ping() final
Execute Ping to SQL Connection using the mysql_ping function.
Int_t DropDataBase(const char *dbname) final
Drop (i.e.
Int_t Shutdown() final
Shutdown the database server.
Basic string class.
Definition: TString.h:136