Permalink
Browse files

[MySQL] Add the mysql pmc to the build. A few fixes so it actually ge…

…nerates the .so and is loadable
  • Loading branch information...
1 parent 4b278c3 commit 3b6ebe48b8affc660820d0c6c6d1aa6b00363579 @Whiteknight committed Apr 14, 2012
Showing with 51 additions and 22 deletions.
  1. +12 −5 Makefile
  2. +1 −1 mysql/pmc/datatable.pmc
  3. +25 −15 mysql/pmc/mysqldbcontext.pmc
  4. +13 −1 setup.winxed
View
17 Makefile
@@ -1,4 +1,4 @@
-all: memcached mongodb
+all: memcached mysql
clean: clean_memcached clean_mongodb
@@ -19,17 +19,24 @@ parrotstore/memcached.pbc: memcached/
## MongoDB
-mongodb: mongocdriver mongodb/*.winxed mongodb/pmc/*.pmc mongodb/include/*.h mongodb/mongo-c-driver/*
+mongodb: mongodb/*.winxed mongodb/pmc/*.pmc mongodb/include/*.h
winxed setup.winxed mongodb build
-mongocdriver:
- scons --directory=./mongodb/mongo-c-driver/
-
clean_mongodb:
winxed setup.winxed mongodb clean
install_mongodb:
winxed setup.winxed mongodb install
+# MySQL
+
+mysql: mysql/pmc/*.pmc
+ winxed setup.winxed mysql build
+
+clean_mysql:
+ winxed setup.winxed mysql clean
+
+install_mysql:
+ winxed setup.winxed mysql install
View
2 mysql/pmc/datatable.pmc
@@ -1,4 +1,4 @@
-pmclass DataTable {
+pmclass DataTable dynpmc auto_attrs {
ATTR PMC *colnames;
ATTR void *data;
View
40 mysql/pmc/mysqldbcontext.pmc
@@ -1,24 +1,34 @@
-pmclass MySQLDbContext {
- ATTR MYSQL *conn;
+#include <mysql/mysql.h>
+#define GET_CONN(s) ((MYSQL*)PARROT_MYSQLDBCONTEXT(s)->conn)
+
+#define STRING_TO_CSTRING(i, s, c, code) do { \
+ char * (c) = Parrot_str_to_cstring((i), (s)); \
+ { \
+ code \
+ } \
+ Parrot_str_free_cstring((c)); \
+} while(0)
+
+pmclass MySQLDbContext dynpmc auto_attrs {
+ ATTR void *conn;
VTABLE void init() {
- MYSQL * const conn = msql_init(NULL);
- PARROT_MYSQLDBCONTEXT(SELF)->conn = conn;
+ MYSQL * const conn = mysql_init(NULL);
+ PARROT_MYSQLDBCONTEXT(SELF)->conn = (void*)conn;
}
VTABLE void destroy() {
- MYSQL * const conn = PARROT_MYSQLDBCONTEXT(SELF)->conn;
- if (conn) {
- msql_close(conn);
- }
+ MYSQL * const conn = GET_CONN(SELF);
+ if (conn)
+ mysql_close(conn);
}
METHOD connect(STRING *server, STRING *username, STRING *password, STRING *db, INTVAL port, INTVAL client_flag) {
- MYSQL * const conn = PARROT_MYSQLDBCONTEXT(SELF)->conn;
- char * const cserver = Parrot_str_to_c_string(INTERP, server);
- char * const cusername = Parrot_str_to_c_string(INTERP, username);
- char * const cpassword = Parrot_str_to_c_string(INTERP, password);
- char * const cdb = db == STRINGNULL ? NULL : Parrot_str_to_c_string(INTERP, db);
+ MYSQL * const conn = GET_CONN(SELF);
+ char * const cserver = Parrot_str_to_cstring(INTERP, server);
+ char * const cusername = Parrot_str_to_cstring(INTERP, username);
+ char * const cpassword = Parrot_str_to_cstring(INTERP, password);
+ char * const cdb = db == STRINGNULL ? NULL : Parrot_str_to_cstring(INTERP, db);
INTVAL stat = mysql_real_connect(conn, cserver, cusername, cpassword, cdb, port, NULL, client_flag);
Parrot_free_cstring(cserver);
@@ -31,7 +41,7 @@ pmclass MySQLDbContext {
}
METHOD query_no_result(STRING * query) {
- MYSQL * const conn = PARROT_MYSQLDBCONTEXT(SELF)->conn;
+ MYSQL * const conn = GET_CONN(SELF);
INTVAL stat;
STRING_TO_CSTRING(INTERP, query, cquery,
stat = mysql_query(conn, cquery);
@@ -42,7 +52,7 @@ pmclass MySQLDbContext {
}
METHOD query(STRING * query) {
- MYSQL * const conn = PARROT_MYSQLDBCONTEXT(SELF)->conn;
+ MYSQL * const conn = GET_CONN(SELF);
INTVAL stat;
STRING_TO_CSTRING(INTERP, query, cquery,
stat = mysql_query(conn, cquery);
View
14 setup.winxed
@@ -13,10 +13,19 @@ function setup_memcached(var parrotstore, var argv)
parrotstore["inst_lib"].push("parrotstore/memcached.pbc");
}
+function setup_mysql(var parrotstore, var argv)
+{
+ parrotstore["dynpmc_cflags"] = "-g";
+ parrotstore["dynpmc_ldflags"] = "-lmysqlclient";
+ parrotstore["dynpmc"]["mysql_group"] = [
+ "mysql/pmc/mysqldbcontext.pmc"
+ ];
+}
+
function setup_mongodb(var parrotstore, var argv)
{
parrotstore["dynpmc_cflags"] = "-g -I./mongodb/mongo-c-driver/src -I./mongodb/include";
- parrotstore["dynpmc_ldflags"] = "mongodb/mongo-c-driver/libbson.a mongodb/mongo-c-driver/libmongoc.a";
+ parrotstore["dynpmc_ldflags"] = "-lbson -lmongoc";
parrotstore["dynpmc"]["mongodb_group"] = [
"mongodb/pmc/mongodbcontext.pmc",
"mongodb/pmc/bsondocument.pmc"
@@ -39,6 +48,9 @@ function setup_main(var parrotstore, string target, var argv)
case "mongodb":
setup_mongodb(parrotstore, argv);
break;
+ case "mysql":
+ setup_mysql(parrotstore, argv);
+ break;
}
}

0 comments on commit 3b6ebe4

Please sign in to comment.