e09ebe9af23e93a73a078bd354239ae98f13109b
[goDBhammer.git] / src / dbconnector.go
1 // um yes... its a db connector
2 package dbconnector
3
4 type DBConnector struct {
5         // err, yes
6 }
7
8 func DBSetup(dbtype string, host string, username string, password string, database string, datamult int, comout chan int)
9 {
10
11         // the job of this function is to bring up the connection and create tables based on dbtype
12         var Dbconn *dbibridge.DBIConnection;
13         
14         Dbconn = dbibridge.DBICreate();
15         
16         dbibridge.DBIConnect(Dbconn, "mysql", host, username, password, database);
17         
18         if dbtype == "mysql" {
19                 dbibridge.ExecSQL("create table WAREHOUSE (
20                 W_ID integer NOT NULL,
21                 W_NAME CHARACTER(10),
22                 W_STREET_1 CHARACTER(20),
23                 W_STREET_2 CHARACTER(20),
24                 W_CITY CHARACTER(20),
25                 W_STATE CHARACTER(2),
26                 W_ZIP CHARACTER(9),
27                 W_TAX integer,
28                 W_YTD integer,
29                 PRIMARY KEY(W_ID))");
30
31                 dbibridge.ExecSQL("create table DISTRICT (
32                 D_ID integer NOT NULL,
33                 D_W_ID integer NOT NULL,
34                 D_NAME CHARACTER(10),
35                 D_STREET_1 CHARACTER(20),
36                 D_STREET_2 CHARACTER(20),
37                 D_CITY CHARACTER(20),
38                 D_STATE CHARACTER(2),
39                 D_ZIP CHARACTER(9),
40                 D_TAX integer,
41                 D_YTD integer,
42                 D_NEXT_O_ID integer,
43                 PRIMARY KEY(D_W_ID, D_ID))");
44                 
45                 dbibridge.ExecSQL("create table ITEM (
46                 I_ID integer NOT NULL,
47                 I_IM_ID integer,
48                 I_NAME CHARACTER(24),
49                 I_PRICE integer,
50                 I_DATA CHARACTER(50),
51                 PRIMARY KEY(I_ID))");           
52         }
53
54         dbibridge.DBIDisconnect(Dbconn);
55 }
56
57
58