Makefile..
[goDBhammer.git] / src / dbconnector.go
index 83dc649..fa86e41 100644 (file)
@@ -2,9 +2,12 @@
 package dbconnector
 
 import (
-       "./dbibridge";
+       //"./dbibridge";
+       "dbibridge";
+       //"strings";
        "time";
        "rand";
+       "fmt";
 )
 
 type DBConnector struct {
@@ -14,22 +17,22 @@ type DBConnector struct {
 
 func CreateRandomText(len int) (str string)
 {
-       buf := make([]byte, len+2);
+       buf := make([]byte, len);
 
        rand.Seed(time.Nanoseconds());
        
        for i:=0; i<len; i++ {
-               switch(rand.Int()%3) {
+               switch(rand.Int()%2) {
                 case 0:
-                    buf[i] = uint8(rand.Int()%26+65);
+                    buf[i] = uint8(rand.Int()%22+66);
                 case 1:
-                    buf[i] = uint8(rand.Int()%26+97);
+                    buf[i] = uint8(rand.Int()%22+98);
                 case 2:
-                    buf[i] = uint8(rand.Int()%10+48);
+                    buf[i] = uint8(rand.Int()%9+48);
+               }
+               //buf[i+1] = 0; // this bit pisses off the c.cstring conversion somehow
         }
-        buf[i+1] = 0;
-               
-       }
+       
        
        return string(buf);
 }
@@ -45,6 +48,9 @@ func DBSetup(dbtype string, host string, username string, password string, datab
        dbibridge.DBIConnect(Dbconn, "mysql", host, username, password, database);
        
        if dbtype == "mysql" {
+               dbibridge.ExecSQL(Dbconn,"drop table WAREHOUSE");
+               dbibridge.ExecSQL(Dbconn,"drop table DISTRICT");
+               dbibridge.ExecSQL(Dbconn,"drop table ITEM");
                dbibridge.ExecSQL(Dbconn,"create table WAREHOUSE ( \
                W_ID integer NOT NULL, \
                W_NAME CHARACTER(10), \
@@ -77,16 +83,29 @@ func DBSetup(dbtype string, host string, username string, password string, datab
                I_NAME CHARACTER(24), \
                I_PRICE integer, \
                I_DATA CHARACTER(50), \
-               PRIMARY KEY(I_ID))");           
+               PRIMARY KEY(I_ID))");
        }
        
-       for i := 1; i < 100; i += 10 {
-               time.Sleep(1000000000);
-               comout <- i;
-       }
-       comout <- 100;
        
-       // now we need to actually create data in the tables...
+       // now we need to actually create data in the tables... this is not how it was meant to be originally, but it'll do
+       // there is dbmult * warehouse
+       // there are 20 districts for each warehosuse
+       // there are 50000 items in each district
+       for i := 0; i < datamult; i++ {
+               whst := fmt.Sprintf("insert into WAREHOUSE values ( %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d)", i, CreateRandomText(9),
+                       CreateRandomText(19), CreateRandomText(19), CreateRandomText(19), CreateRandomText(2), CreateRandomText(8), rand.Int()%50, rand.Int()%100);
+               dbibridge.ExecSQL(Dbconn, whst); 
+               for j:=0; j < 20; j++ {
+                       dtst := fmt.Sprintf("insert into DISTRICT values ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d)", j, i, 
+                               CreateRandomText(9), CreateRandomText(19), CreateRandomText(19), CreateRandomText(19), CreateRandomText(2), CreateRandomText(8), rand.Int()%50, rand.Int()%100, j+1);
+                       dbibridge.ExecSQL(Dbconn, dtst);
+                       for k:=0; k<50000; k++ {
+                               itst := fmt.Sprintf("insert into ITEM values ( %d, %d, '%s', %d, '%s')", (i+1)*(j+1)*(k+1), rand.Int()%50000, 
+                                       CreateRandomText(23), rand.Int()%1000000, CreateRandomText(49));
+                               dbibridge.ExecSQL(Dbconn, itst);
+                       }
+               }
+       }
        
 
        dbibridge.DBIDisconnect(Dbconn);