"./dbibridge";
"time";
"rand";
+ "fmt";
)
type DBConnector struct {
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);
import (
"unsafe";
+ "fmt";
)
type DBIConnection struct {
- dbconn C.dbi_conn;
+ dbconn unsafe.Pointer;
dbinit bool;
}
{
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