table creation, random data and need some more stuff
[goDBhammer.git] / src / dbconnector.go
1 // um yes... its a db connector
2 package dbconnector
3
4 import (
5         "./dbibridge";
6         "time";
7         "rand";
8 )
9
10 type DBConnector struct {
11         // err, yes
12 }
13
14
15 func CreateRandomText(len int) (str string)
16 {
17         buf := make([]byte, len+2);
18
19         rand.Seed(time.Nanoseconds());
20         
21         for i:=0; i<len; i++ {
22                 switch(rand.Int()%3) {
23                 case 0:
24                     buf[i] = uint8(rand.Int()%26+65);
25                 case 1:
26                     buf[i] = uint8(rand.Int()%26+97);
27                 case 2:
28                     buf[i] = uint8(rand.Int()%10+48);
29         }
30         buf[i+1] = 0;
31                 
32         }
33         
34         return string(buf);
35 }
36
37 func DBSetup(dbtype string, host string, username string, password string, database string, datamult int, comout chan int)
38 {
39
40         // the job of this function is to bring up the connection and create tables based on dbtype
41         var Dbconn *dbibridge.DBIConnection;
42         
43         Dbconn = dbibridge.DBICreate();
44         
45         dbibridge.DBIConnect(Dbconn, "mysql", host, username, password, database);
46         
47         if dbtype == "mysql" {
48                 dbibridge.ExecSQL(Dbconn,"create table WAREHOUSE ( \
49                 W_ID integer NOT NULL, \
50                 W_NAME CHARACTER(10), \
51                 W_STREET_1 CHARACTER(20), \
52                 W_STREET_2 CHARACTER(20), \
53                 W_CITY CHARACTER(20), \
54                 W_STATE CHARACTER(2), \
55                 W_ZIP CHARACTER(9), \
56                 W_TAX integer, \
57                 W_YTD integer, \
58                 PRIMARY KEY(W_ID))");
59
60                 dbibridge.ExecSQL(Dbconn,"create table DISTRICT ( \
61                 D_ID integer NOT NULL, \
62                 D_W_ID integer NOT NULL, \
63                 D_NAME CHARACTER(10), \
64                 D_STREET_1 CHARACTER(20), \
65                 D_STREET_2 CHARACTER(20), \
66                 D_CITY CHARACTER(20), \
67                 D_STATE CHARACTER(2), \
68                 D_ZIP CHARACTER(9), \
69                 D_TAX integer, \
70                 D_YTD integer, \
71                 D_NEXT_O_ID integer, \
72                 PRIMARY KEY(D_W_ID, D_ID))");
73                 
74                 dbibridge.ExecSQL(Dbconn,"create table ITEM ( \
75                 I_ID integer NOT NULL, \
76                 I_IM_ID integer, \
77                 I_NAME CHARACTER(24), \
78                 I_PRICE integer, \
79                 I_DATA CHARACTER(50), \
80                 PRIMARY KEY(I_ID))");           
81         }
82         
83         for i := 1; i < 100; i += 10 {
84                 time.Sleep(1000000000);
85                 comout <- i;
86         }
87         comout <- 100;
88         
89         // now we need to actually create data in the tables...
90         
91
92         dbibridge.DBIDisconnect(Dbconn);
93 }
94
95
96