import (
"./dbibridge";
+ //"strings";
"time";
"rand";
"fmt";
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);
}
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), \
I_PRICE integer, \
I_DATA CHARACTER(50), \
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);
}
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++ {
+ 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<1; k++ {
- itst := fmt.Sprintf("insert into ITEM values ( %d, %d, '%s', %d, '%s')", i*j*k, rand.Int()%50000,
+ 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);
}
import (
"unsafe";
- "fmt";
+ //"fmt";
+ //"strings";
)
type DBIConnection struct {
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_set_option(thisDBConn.dbconn, C.CString("encoding"), C.CString("UTF-8"));
C.dbi_conn_connect(thisDBConn.dbconn);
thisDBConn.dbinit = true;
func ExecSQL(thisDBConn *DBIConnection, SQL string)
{
- fmt.Printf("%s;\n", 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(thisDBConn.dbconn);
-}
\ No newline at end of file
+}