1 // um yes... its a db connector
11 type DBConnector struct {
16 func CreateRandomText(len int) (str string)
18 buf := make([]byte, len+2);
20 rand.Seed(time.Nanoseconds());
22 for i:=0; i<len; i++ {
23 switch(rand.Int()%3) {
25 buf[i] = uint8(rand.Int()%26+65);
27 buf[i] = uint8(rand.Int()%26+97);
29 buf[i] = uint8(rand.Int()%10+48);
38 func DBSetup(dbtype string, host string, username string, password string, database string, datamult int, comout chan int)
41 // the job of this function is to bring up the connection and create tables based on dbtype
42 var Dbconn *dbibridge.DBIConnection;
44 Dbconn = dbibridge.DBICreate();
46 dbibridge.DBIConnect(Dbconn, "mysql", host, username, password, database);
48 if dbtype == "mysql" {
49 dbibridge.ExecSQL(Dbconn,"create table WAREHOUSE ( \
50 W_ID integer NOT NULL, \
51 W_NAME CHARACTER(10), \
52 W_STREET_1 CHARACTER(20), \
53 W_STREET_2 CHARACTER(20), \
54 W_CITY CHARACTER(20), \
55 W_STATE CHARACTER(2), \
61 dbibridge.ExecSQL(Dbconn,"create table DISTRICT ( \
62 D_ID integer NOT NULL, \
63 D_W_ID integer NOT NULL, \
64 D_NAME CHARACTER(10), \
65 D_STREET_1 CHARACTER(20), \
66 D_STREET_2 CHARACTER(20), \
67 D_CITY CHARACTER(20), \
68 D_STATE CHARACTER(2), \
72 D_NEXT_O_ID integer, \
73 PRIMARY KEY(D_W_ID, D_ID))");
75 dbibridge.ExecSQL(Dbconn,"create table ITEM ( \
76 I_ID integer NOT NULL, \
78 I_NAME CHARACTER(24), \
80 I_DATA CHARACTER(50), \
82 whst := fmt.Sprintf("insert into WAREHOUSE values ( %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d)", 10, CreateRandomText(9),
83 CreateRandomText(19), CreateRandomText(19), CreateRandomText(19), CreateRandomText(2), CreateRandomText(8), rand.Int()%50, rand.Int()%100);
84 dbibridge.ExecSQL(Dbconn, whst);
88 // now we need to actually create data in the tables... this is not how it was meant to be originally, but it'll do
89 // there is dbmult * warehouse
90 // there are 20 districts for each warehosuse
91 // there are 50000 items in each district
92 for i := 0; i < datamult; i++ {
93 whst := fmt.Sprintf("insert into WAREHOUSE values ( %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d)", i, CreateRandomText(9),
94 CreateRandomText(19), CreateRandomText(19), CreateRandomText(19), CreateRandomText(2), CreateRandomText(8), rand.Int()%50, rand.Int()%100);
95 dbibridge.ExecSQL(Dbconn, whst);
96 for j:=0; j < 1; j++ {
97 dtst := fmt.Sprintf("insert into DISTRICT values ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d)", j, i,
98 CreateRandomText(9), CreateRandomText(19), CreateRandomText(19), CreateRandomText(19), CreateRandomText(2), CreateRandomText(8), rand.Int()%50, rand.Int()%100, j+1);
99 dbibridge.ExecSQL(Dbconn, dtst);
101 itst := fmt.Sprintf("insert into ITEM values ( %d, %d, '%s', %d, '%s')", i*j*k, rand.Int()%50000,
102 CreateRandomText(23), rand.Int()%1000000, CreateRandomText(49));
103 dbibridge.ExecSQL(Dbconn, itst);
109 dbibridge.DBIDisconnect(Dbconn);