summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Garrett <jeff@jgarrett.org>2007-09-08 01:23:44 +0000
committerJeff Garrett <jeff@jgarrett.org>2007-09-08 01:23:44 +0000
commite4ed779e28ab96ce4ed56c7c84b667fa8f84cac1 (patch)
tree8291b4ffb0f4ae248e3bfb583a322b4912389c1b
parentfc863b6bcdd42e879788cc8f14c6eb818a0818ae (diff)
Add configuration for external MySQL server
Remove MySQL embedded server
-rw-r--r--ChangeLog6
-rw-r--r--configure.ac3
-rw-r--r--src/db.c28
-rw-r--r--src/main.c16
4 files changed, 24 insertions, 29 deletions
diff --git a/ChangeLog b/ChangeLog
index cf5246a..e84f1c2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-09-08 Jeff Garrett <jeff@jgarrett.org>
+
+ * src/main.c: Add configuration for external MySQL server
+ * configure.ac:
+ * src/db.c: Remove MySQL embedded server
+
2005-10-26 Ian McIntosh <ian_mcintosh@linuxadvocate.org>
* src/*: Fix all compiler warnings that showed up after adding -Wall.
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();