ROOT logo

From $ROOTSYS/tutorials/sql/sqlcreatedb.C

void sqlcreatedb()
{
   // Create a runcatalog table in a MySQL test database.
   
   // read in runcatalog table definition
   FILE *fp = fopen("runcatalog.sql", "r");
   const char sql[4096];
   fread(sql, 1, 4096, fp);
   fclose(fp);
   
   // open connection to MySQL server on localhost
   TSQLServer *db = TSQLServer::Connect("mysql://localhost/test", "nobody", "");
   
   TSQLResult *res;

   // create new table (delete old one first if exists)
   res = db->Query("DROP TABLE runcatalog");
   delete res;
   
   res = db->Query(sql);
   delete res;
   
   delete db;
}
 sqlcreatedb.C:1
 sqlcreatedb.C:2
 sqlcreatedb.C:3
 sqlcreatedb.C:4
 sqlcreatedb.C:5
 sqlcreatedb.C:6
 sqlcreatedb.C:7
 sqlcreatedb.C:8
 sqlcreatedb.C:9
 sqlcreatedb.C:10
 sqlcreatedb.C:11
 sqlcreatedb.C:12
 sqlcreatedb.C:13
 sqlcreatedb.C:14
 sqlcreatedb.C:15
 sqlcreatedb.C:16
 sqlcreatedb.C:17
 sqlcreatedb.C:18
 sqlcreatedb.C:19
 sqlcreatedb.C:20
 sqlcreatedb.C:21
 sqlcreatedb.C:22
 sqlcreatedb.C:23
 sqlcreatedb.C:24
 sqlcreatedb.C:25