From 52618e1a8ebd86ebb31b7109a65cfd5f6f82bf53 Mon Sep 17 00:00:00 2001 From: Paul J R Date: Sat, 14 Nov 2009 03:40:54 +1100 Subject: [PATCH] tried to use the package.var.function() syntax with very little joy... quite odd. --- src/dbibridge.8 | Bin 5379 -> 0 bytes src/dbibridge.go | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- src/dbibridge.go.or | 28 ---------------------------- src/makeit | 6 +++--- src/webconnector.go | 19 +++++++++++++------ 5 files changed, 62 insertions(+), 40 deletions(-) delete mode 100644 src/dbibridge.8 delete mode 100644 src/dbibridge.go.or mode change 100755 => 100644 src/makeit diff --git a/src/dbibridge.8 b/src/dbibridge.8 deleted file mode 100644 index b7d3036f58a6c67eb3d433bbd2a0fb3501dd6711..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5379 zcmb7I+fEx-6dhj%upu~vdkE%m3kHncv`rI<98p>lB~Oh+r1qgw<=}x>u|3F`T+}vF z`vH|u6{+ue=nqulrBC!X@*PoCRciOzXU=5?Cv8SiJhNtB)?RzhnZtZ^^OL*~!L!4# z(>)Tk<8IihbsKxNX7jl?2--oX)(z@nzZ15|tp2d^u+yj?1eJqOG}_{@w)ePp5QqhH zV}YzhqlIYs{L+#T)v6ATJI2E}c|yL=a_PSE53(o zK0lv-;oVN%s(SqMC~O7l?67v+?5NYD&Yn66_L_~uqhRA{*m-BBw`>k%JMvxE0|A&t48(t0|{s$-51_gp9yt# zS|Js^8k@ZQn>hDvWm3Zwqu;~`nn5eF7|#-={@qkzo*g{zdGt#p28=^vpJaUS;cZaM zImN9p!SY+WxGGAON@dlXQz1_VWKPlY2Po-oYLJNMUE=MqU8Byb@=}B2e-iurmb#2C zxROC?%-QJ^T>_#F_9($AW#}NR&`dSj2WO`XcY|g#EDM^CX8r5-LKJ3XNOJHC9DG0Q z(4(hsU3ho&VRpGs;k)~gsNhJXvX%vu5GArGi}0v&yVD6fR+(X0cx83J=xCxIA(|l+ zd2*3v2o1vwjW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S+j;xAkBa*}Pt7F#kBNVXAACZwN< zB_lv5vwy0;|ND^|REY$j_o`_GLK9A3srYM!!Ou*v97Ye6uRQz>A z1zicreziBuM=X0pNAHexEAx$UxShHB0y_VHNvwN>Z$FDT2nnE(I) diff --git a/src/dbibridge.go b/src/dbibridge.go index 7f0bcf8..0b9b97a 100644 --- a/src/dbibridge.go +++ b/src/dbibridge.go @@ -1,8 +1,51 @@ package dbibridge -import "fmt" +// #include +// #include +import "C" -func dbiconnect() +import ( + "unsafe"; +) + +type DBConnection struct { + dbconn C.dbi_conn; + dbinit bool; +} + +func DBICreate()(connection *DBConnection) +{ + var dbCon *DBConnection; + + dbCon = new(DBConnection); + dbCon.dbinit = false; + + return dbCon; +} + +//func (thisDBConn *DBConnection)DBIConnect(dbtype string, host string, username string, password string, database string) +// for some reason, the above doesnt work how i'd expect.. +func DBIConnect(thisDBConn *DBConnection, dbtype string, host string, username string, password string, database string) { - fmt.Printf("Hello, world\n"); + C.dbi_initialize(nil); + + thisDBConn.dbconn = 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)); + + thisDBConn.dbinit = true; } + +func ExecSQL(thisDBConn *DBConnection, SQL string) +{ + C.dbi_conn_query((unsafe.Pointer)(thisDBConn.dbconn), C.CString(SQL)); +} + +func DBIDisconnect(thisDBConn *DBConnection) +{ + C.dbi_conn_close((unsafe.Pointer)(thisDBConn.dbconn)); +} \ No newline at end of file diff --git a/src/dbibridge.go.or b/src/dbibridge.go.or deleted file mode 100644 index 0d5bad4..0000000 --- a/src/dbibridge.go.or +++ /dev/null @@ -1,28 +0,0 @@ -package dbibridge - -// #include -// #include -import "C" - -import ( - "unsafe"; -) - -func dbiconnect() -{ - - C.dbi_initialize(nil); - - myVar := C.dbi_conn_new(C.CString("mysql")); - - C.dbi_conn_set_option((unsafe.Pointer)(myVar), C.CString("host"), C.CString("localhost")); - C.dbi_conn_set_option((unsafe.Pointer)(myVar), C.CString("username"), C.CString("your_name")); - C.dbi_conn_set_option((unsafe.Pointer)(myVar), C.CString("username"), C.CString("your_name")); - C.dbi_conn_set_option((unsafe.Pointer)(myVar), C.CString("password"), C.CString("your_password")); - C.dbi_conn_set_option((unsafe.Pointer)(myVar), C.CString("dbname"), C.CString("your_dbname")); - C.dbi_conn_set_option((unsafe.Pointer)(myVar), C.CString("encoding"), C.CString("UTF-8")); - C.dbi_conn_connect((unsafe.Pointer)(myVar)); - - - -} diff --git a/src/makeit b/src/makeit old mode 100755 new mode 100644 index cd40c77..fbcd8fc --- a/src/makeit +++ b/src/makeit @@ -6,10 +6,10 @@ cgo dbibridge.go gopack grc dbibridge.a _dbibridge_.8 dbibridge.cgo3.8 #cp dbibridge.a /export/src/external/golang//pkg/linux_386/dbibridge.a gcc -m32 -fPIC -O2 -o dbibridge.cgo4.o -c dbibridge.cgo4.c -gcc -m32 -shared -lpthread -lm -o dbibridge.so dbibridge.cgo4.o -#cp dbibridge.so /export/src/external/golang//pkg/linux_386/./dbibridge.so +gcc -m32 -shared -lpthread -lm -ldbi -o dbibridge.so dbibridge.cgo4.o +cp dbibridge.so /export/src/external/golang//pkg/linux_386/./dbibridge_dbibridge.so 8g -I. webconnector.go -8l webconnector.8 +8l -L. webconnector.8 diff --git a/src/webconnector.go b/src/webconnector.go index 546341d..5fe61aa 100644 --- a/src/webconnector.go +++ b/src/webconnector.go @@ -15,11 +15,18 @@ func HelloServer(c *http.Conn, req *http.Request) { } func main() { - dbibridge.dbiconnect(); - http.Handle("/hello", http.HandlerFunc(HelloServer)); - err := http.ListenAndServe(":12345", nil); - if err != nil { - panic("ListenAndServe: ", err.String()) - } + + var Dbconn *dbibridge.DBConnection; + + Dbconn = dbibridge.DBICreate(); + + dbibridge.DBIConnect(Dbconn, "mysql", "localhost", "root", "password", "zm"); + dbibridge.ExecSQL(Dbconn, "create table asdf (asdf int)"); + dbibridge.DBIDisconnect(Dbconn); + //http.Handle("/hello", http.HandlerFunc(HelloServer)); + //err := http.ListenAndServe(":12345", nil); + //if err != nil { + ////panic("ListenAndServe: ", err.String()) + //} } -- 1.7.0.4