From: Paul J R Date: Sun, 15 Nov 2009 16:48:30 +0000 (+1100) Subject: stuck with a bitch of a problem X-Git-Url: http://git.pjr.cc/?a=commitdiff_plain;h=ff6679f750e301016b3e070d7d6ffa41048004b8;p=goDBhammer.git stuck with a bitch of a problem --- diff --git a/src/dbconnector.go b/src/dbconnector.go index 83dc649..637aa84 100644 --- a/src/dbconnector.go +++ b/src/dbconnector.go @@ -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); diff --git a/src/dbibridge.go b/src/dbibridge.go index 64b7d1b..fe26e60 100644 --- a/src/dbibridge.go +++ b/src/dbibridge.go @@ -6,10 +6,11 @@ import "C" import ( "unsafe"; + "fmt"; ) type DBIConnection struct { - dbconn C.dbi_conn; + dbconn unsafe.Pointer; dbinit bool; } @@ -29,23 +30,26 @@ func DBIConnect(thisDBConn *DBIConnection, dbtype string, host string, username { C.dbi_initialize(nil); - thisDBConn.dbconn = C.dbi_conn_new(C.CString(dbtype)); + thisDBConn.dbconn = (unsafe.Pointer)(C.dbi_conn_new(C.CString(dbtype))); - C.dbi_conn_set_option((unsafe.Pointer)(thisDBConn.dbconn), C.CString("host"), C.CString(host)); - C.dbi_conn_set_option((unsafe.Pointer)(thisDBConn.dbconn), C.CString("username"), C.CString(username)); - C.dbi_conn_set_option((unsafe.Pointer)(thisDBConn.dbconn), C.CString("password"), C.CString(password)); - C.dbi_conn_set_option((unsafe.Pointer)(thisDBConn.dbconn), C.CString("dbname"), C.CString(database)); - C.dbi_conn_connect((unsafe.Pointer)(thisDBConn.dbconn)); + C.dbi_conn_set_option(thisDBConn.dbconn, C.CString("host"), C.CString(host)); + C.dbi_conn_set_option(thisDBConn.dbconn, C.CString("username"), C.CString(username)); + C.dbi_conn_set_option(thisDBConn.dbconn, C.CString("password"), C.CString(password)); + C.dbi_conn_set_option(thisDBConn.dbconn, C.CString("dbname"), C.CString(database)); + C.dbi_conn_connect(thisDBConn.dbconn); thisDBConn.dbinit = true; } func ExecSQL(thisDBConn *DBIConnection, SQL string) { - C.dbi_conn_query((unsafe.Pointer)(thisDBConn.dbconn), C.CString(SQL)); + fmt.Printf("%s;\n", SQL); + res := C.dbi_conn_query(thisDBConn.dbconn, C.CString(SQL)); + + C.dbi_result_free((unsafe.Pointer)(res)); } func DBIDisconnect(thisDBConn *DBIConnection) { - C.dbi_conn_close((unsafe.Pointer)(thisDBConn.dbconn)); + C.dbi_conn_close(thisDBConn.dbconn); } \ No newline at end of file diff --git a/src/makeit b/src/makeit old mode 100644 new mode 100755