table creation, random data and need some more stuff
[goDBhammer.git] / src / dbconnector.go
index f8b9131..83dc649 100644 (file)
@@ -1 +1,96 @@
-// um yes... its a db connector
\ No newline at end of file
+// um yes... its a db connector
+package dbconnector
+
+import (
+       "./dbibridge";
+       "time";
+       "rand";
+)
+
+type DBConnector struct {
+       // err, yes
+}
+
+
+func CreateRandomText(len int) (str string)
+{
+       buf := make([]byte, len+2);
+
+       rand.Seed(time.Nanoseconds());
+       
+       for i:=0; i<len; i++ {
+               switch(rand.Int()%3) {
+                case 0:
+                    buf[i] = uint8(rand.Int()%26+65);
+                case 1:
+                    buf[i] = uint8(rand.Int()%26+97);
+                case 2:
+                    buf[i] = uint8(rand.Int()%10+48);
+        }
+        buf[i+1] = 0;
+               
+       }
+       
+       return string(buf);
+}
+
+func DBSetup(dbtype string, host string, username string, password string, database string, datamult int, comout chan int)
+{
+
+       // the job of this function is to bring up the connection and create tables based on dbtype
+       var Dbconn *dbibridge.DBIConnection;
+       
+       Dbconn = dbibridge.DBICreate();
+       
+       dbibridge.DBIConnect(Dbconn, "mysql", host, username, password, database);
+       
+       if dbtype == "mysql" {
+               dbibridge.ExecSQL(Dbconn,"create table WAREHOUSE ( \
+               W_ID integer NOT NULL, \
+               W_NAME CHARACTER(10), \
+               W_STREET_1 CHARACTER(20), \
+               W_STREET_2 CHARACTER(20), \
+               W_CITY CHARACTER(20), \
+               W_STATE CHARACTER(2), \
+               W_ZIP CHARACTER(9), \
+               W_TAX integer, \
+               W_YTD integer, \
+               PRIMARY KEY(W_ID))");
+
+               dbibridge.ExecSQL(Dbconn,"create table DISTRICT ( \
+               D_ID integer NOT NULL, \
+               D_W_ID integer NOT NULL, \
+               D_NAME CHARACTER(10), \
+               D_STREET_1 CHARACTER(20), \
+               D_STREET_2 CHARACTER(20), \
+               D_CITY CHARACTER(20), \
+               D_STATE CHARACTER(2), \
+               D_ZIP CHARACTER(9), \
+               D_TAX integer, \
+               D_YTD integer, \
+               D_NEXT_O_ID integer, \
+               PRIMARY KEY(D_W_ID, D_ID))");
+               
+               dbibridge.ExecSQL(Dbconn,"create table ITEM ( \
+               I_ID integer NOT NULL, \
+               I_IM_ID integer, \
+               I_NAME CHARACTER(24), \
+               I_PRICE integer, \
+               I_DATA CHARACTER(50), \
+               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...
+       
+
+       dbibridge.DBIDisconnect(Dbconn);
+}
+
+
+