[Roadster] [PATCH] Remove the MySQL embedded server

Jeff Garrett jeff at jgarrett.org
Sun Aug 19 15:52:58 PDT 2007


Embedded server support does not exist in MySQL 5.0.
To configure which external MySQL server to use, create a
file ~/roadster/roadster.conf:
[mysql]
host = $host
user = $user
password = $password
database = $database

If the file does not exist, or some parameters are not
specified, default values will be used (localhost, same user,
no password, no database).

Signed-off-by: Jeff Garrett <jeff at jgarrett.org>
---
 configure.ac |    3 +--
 src/db.c     |   28 ++--------------------------
 src/main.c   |   16 +++++++++++++++-
 3 files changed, 18 insertions(+), 29 deletions(-)

diff --git a/configure.ac b/configure.ac
index 11b49fe..3933483 100644
--- a/configure.ac
+++ b/configure.ac
@@ -92,8 +92,7 @@ else
     AC_MSG_CHECKING(MySQL libraries)
     MYSQL_VERSION=`${mysqlconfig} --version`
 
-    MYSQL_LIBS="`${mysqlconfig} --libmysqld-libs` -lmygcc -lsupc++"
-    AC_DEFINE([HAVE_MYSQL_EMBED], [1], [Have embedded MySQL])
+    MYSQL_LIBS=`${mysqlconfig} --libs`
 
     AC_MSG_RESULT($MYSQL_LIBS)
     AC_MSG_CHECKING(mysql includes)
diff --git a/src/db.c b/src/db.c
index 83edf36..953ed64 100644
--- a/src/db.c
+++ b/src/db.c
@@ -22,12 +22,7 @@
  */
 
 #include <mysql.h>
-
-#define HAVE_MYSQL_EMBED
-
-#ifdef HAVE_MYSQL_EMBED
-# include <mysql_embed.h>
-#endif
+#include <glib.h>
 
 #include <stdlib.h>
 #include <gtk/gtk.h>
@@ -68,19 +63,9 @@ db_connection_t* g_pDB = NULL;
 // call once on program start-up
 void db_init()
 {
-#ifdef HAVE_MYSQL_EMBED
-	gchar* pszDataDir = g_strdup_printf("%s/.roadster/data", g_get_home_dir());
-	gchar* pszSetDataDirCommand = g_strdup_printf("--datadir=%s", pszDataDir);
 	gchar* pszSetQueryCacheSize = g_strdup_printf("--query-cache-size=%dMB", 40);
 	gchar* pszKeyBufferSize	= g_strdup_printf("--key-buffer-size=%dMB", 32);
 
-#ifdef USE_GNOME_VFS
-	// Create directory if it doesn't exist
-	if(GNOME_VFS_OK != gnome_vfs_make_directory(pszDataDir, 0700)) {
-		// no big deal, probably already exists (should we check?)
-	}
-#endif
-
 	gchar* apszServerOptions[] = {
 		"",	// program name -- unused
 
@@ -97,29 +82,20 @@ void db_init()
 		"--ft-stopword-file=''",	// non-existant stopword file. we don't want ANY stopwords (words that are ignored)
 
 		// Misc options
-		pszKeyBufferSize,
-		pszSetDataDirCommand
+		pszKeyBufferSize
 	};
 
-	// Initialize the embedded server
-	// NOTE: if not linked with libmysqld, this call will do nothing (but will succeed)
  	if(mysql_server_init(G_N_ELEMENTS(apszServerOptions), apszServerOptions, NULL) != 0) {
 		return;
 	}
-	g_free(pszDataDir);
-	g_free(pszSetDataDirCommand);
 	g_free(pszSetQueryCacheSize);
 	g_free(pszKeyBufferSize);
-#endif
 }
 
 // call once on program shut-down
 void db_deinit()
 {
-#ifdef HAVE_MYSQL_EMBED
-	// Close embedded server if present
 	mysql_server_end();
-#endif
 }
 
 gboolean db_query(const gchar* pszSQL, db_resultset_t** ppResultSet)
diff --git a/src/main.c b/src/main.c
index 406aed8..61aac95 100644
--- a/src/main.c
+++ b/src/main.c
@@ -132,6 +132,12 @@ void main_debug_insert_test_data()
 
 gboolean main_init(void)
 {
+	char *db_host = NULL, *db_user = NULL;
+	char *db_passwd = NULL, *db_dbname = NULL;
+	GKeyFile *keyfile;
+
+	char *conffile = g_strdup_printf("%s/.roadster/roadster.conf", g_get_home_dir());
+
 #ifdef USE_GNOME_VFS
 	if(!gnome_vfs_init()) {	
 		g_warning("gnome_vfs_init failed\n");
@@ -159,8 +165,16 @@ gboolean main_init(void)
 	g_print("initializing db\n");
 	db_init();
 
+	keyfile = g_key_file_new();
+	if (g_key_file_load_from_file(keyfile, conffile, G_KEY_FILE_NONE, NULL))
+	{
+		db_host   = g_key_file_get_string(keyfile, "mysql", "host", NULL);
+		db_user   = g_key_file_get_string(keyfile, "mysql", "user", NULL);
+		db_passwd = g_key_file_get_string(keyfile, "mysql", "passwordd", NULL);
+		db_dbname = g_key_file_get_string(keyfile, "mysql", "database", NULL);
+	}
 	g_print("connecting to db\n");
-	db_connect(NULL, NULL, NULL, "");	// Connect to internal DB
+	db_connect(db_host, db_user, db_passwd, db_dbname);
 
 	g_print("creating database tables\n");
 	db_create_tables();
-- 
1.4.4.2



More information about the roadster mailing list