Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
sqlcreatedb.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_sql
3/// Create a runcatalog table in a MySQL test database.
4///
5/// \macro_code
6///
7/// \author Sergey Linev
8
9void sqlcreatedb()
10{
11 // read in runcatalog table definition
12 FILE *fp = fopen("runcatalog.sql", "r");
13 const char sql[4096];
14 fread(sql, 1, 4096, fp);
15 fclose(fp);
16
17 // open connection to MySQL server on localhost
18 TSQLServer *db = TSQLServer::Connect("mysql://localhost/test", "nobody", "");
19
20 TSQLResult *res;
21
22 // create new table (delete old one first if exists)
23 res = db->Query("DROP TABLE runcatalog");
24 delete res;
25
26 res = db->Query(sql);
27 delete res;
28
29 delete db;
30}
virtual TSQLResult * Query(const char *sql)=0
static TSQLServer * Connect(const char *db, const char *uid, const char *pw)
The db should be of the form: <dbms>://<host>[:<port>][/<database>], e.g.: mysql://pcroot....