stuck with a bitch of a problem
[goDBhammer.git] / src / dbconnector.go
index 83dc649..637aa84 100644 (file)
@@ -5,6 +5,7 @@ import (
        "./dbibridge";
        "time";
        "rand";
+       "fmt";
 )
 
 type DBConnector struct {
@@ -77,16 +78,32 @@ 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))");
+               whst := fmt.Sprintf("insert into WAREHOUSE values ( %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d)", 10, CreateRandomText(9),
+                       CreateRandomText(19), CreateRandomText(19), CreateRandomText(19), CreateRandomText(2), CreateRandomText(8), rand.Int()%50, rand.Int()%100);
+          dbibridge.ExecSQL(Dbconn, whst);
        }
        
-       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 < 1; 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<1; k++ {
+                               itst := fmt.Sprintf("insert into ITEM values ( %d, %d, '%s', %d, '%s')", i*j*k, rand.Int()%50000, 
+                                       CreateRandomText(23), rand.Int()%1000000, CreateRandomText(49));
+                               dbibridge.ExecSQL(Dbconn, itst);
+                       }
+               }
+       }
        
 
        dbibridge.DBIDisconnect(Dbconn);