summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpixel <pixel>2003-08-21 16:49:52 +0000
committerpixel <pixel>2003-08-21 16:49:52 +0000
commit23974eb093c83a5e6f7b1109e0f739ad7a870aac (patch)
treeb3cabc2eae9dde5689e8182f06036fcb6c417c34
parent567a5619d98b17276479055512a469f1571c4ab4 (diff)
Starting MySQL code
-rw-r--r--configure.ac1
-rw-r--r--include/BString.h2
-rw-r--r--include/Makefile.am2
-rw-r--r--include/SQL.h20
-rw-r--r--lib/Makefile.am6
-rw-r--r--lib/SQL.cc25
-rw-r--r--lib/String.cc4
-rw-r--r--m4/mysql.m453
8 files changed, 109 insertions, 4 deletions
diff --git a/configure.ac b/configure.ac
index a5a7959..b2b759d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,6 +23,7 @@ AC_C_BIGENDIAN
# Checks for libraries.
AC_CHECK_LIB([c], [printf])
+AM_PATH_MYSQL(AC_DEFINE(HAVE_MYSQL, 1, [Have MySQL]))
# Checks for header files.
AC_FUNC_ALLOCA
diff --git a/include/BString.h b/include/BString.h
index ab4f5e5..b5a273f 100644
--- a/include/BString.h
+++ b/include/BString.h
@@ -73,4 +73,6 @@ std::istream & operator>>(std::istream &, String &);
String operator+(const char *, const String &);
+bool compare(String, String);
+
#endif
diff --git a/include/Makefile.am b/include/Makefile.am
index 583a97d..a84dd81 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -2,6 +2,6 @@ pkginclude_HEADERS = \
Exceptions.h Handle.h BString.h Output.h Socket.h HttpServ.h Variables.h Menu.h \
Action.h Message.h Form.h Confirm.h Table.h IRC.h Task.h Buffer.h generic.h \
CopyJob.h ReadJob.h Regex.h TaskMan.h InPipe.h OutPipe.h Input.h Image.h \
-Main.h Color.h GMPString.h
+Main.h Color.h GMPString.h SQL.h
noinst_HEADERS = gettext.h
diff --git a/include/SQL.h b/include/SQL.h
new file mode 100644
index 0000000..ee28eb0
--- /dev/null
+++ b/include/SQL.h
@@ -0,0 +1,20 @@
+#ifndef __SQL_H__
+#define __SQL_H__
+
+#include <set>
+#include <mysql.h>
+#include <Exceptions.h>
+
+//typedef AssocArray std::set<String, compare>;
+
+class SQLConnection : public Base {
+ public:
+ SQLConnection(String host, String user, String passwd, String db, int port = 3306, String socket = "", unsigned long clags = 0) throw (GeneralException);
+ ~SQLConnection();
+ void query(String) throw (GeneralException);
+ private:
+ MYSQL con;
+ MYSQL_RES * res;
+};
+
+#endif
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 6719ad7..c843753 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -1,7 +1,7 @@
localedir = $(datadir)/locale
DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
-AM_CFLAGS = -O3 -Wall -Wstrict-prototypes -g
-AM_CXXFLAGS = -O3 -Wall -Wstrict-prototypes -g
+AM_CPPFLAGS = -O3 -Wall -Wstrict-prototypes -g @MYSQL_CFLAGS@
+LIBS = @MYSQL_LIBS@
INCLUDES = -I.. -I../include -I$(includedir)
lib_LTLIBRARIES = libBaltisot.la
@@ -9,4 +9,4 @@ libBaltisot_la_SOURCES = Action.cc Buffer.cc checkargs.c Confirm.cc CopyJob.cc \
datecalc.c Exceptions.cc Form.cc GMPString.cc Handle.cc HttpServ.cc Image.cc \
InPipe.cc Input.cc IRC.cc Main.cc Menu.cc Message.cc OutPipe.cc Output.cc \
ReadJob.cc Regex.cc Socket.cc String.cc Table.cc Task.cc TaskMan.cc \
-Variables.cc generic.cc fileutils.cc
+Variables.cc generic.cc fileutils.cc SQL.cc
diff --git a/lib/SQL.cc b/lib/SQL.cc
new file mode 100644
index 0000000..9091c23
--- /dev/null
+++ b/lib/SQL.cc
@@ -0,0 +1,25 @@
+#include "SQL.h"
+
+SQLConnection::SQLConnection(String host, String user, String passwd,
+ String db, int port, String socket,
+ unsigned long cflags) throw (GeneralException) : res(0) {
+ mysql_init(&con);
+
+ char * p;
+
+ if (!mysql_real_connect(&con,
+ p = ((ugly_string)(host)).p ? p : 0,
+ ((ugly_string)(user)).p,
+ ((ugly_string)(passwd)).p,
+ ((ugly_string)(db)).p, port,
+ ((ugly_string)(socket)).p, cflags)) {
+ throw GeneralException(String("Could not connect to MySQL host ") + p);
+ }
+}
+
+SQLConnection::~SQLConnection() {
+ mysql_close(&con);
+}
+
+void SQLConnection::query(String q) throw(GeneralException) {
+}
diff --git a/lib/String.cc b/lib/String.cc
index 265883f..402424c 100644
--- a/lib/String.cc
+++ b/lib/String.cc
@@ -474,3 +474,7 @@ String & String::tolower() {
return *this;
}
+
+bool compare(String a, String b) {
+ return a < b;
+}
diff --git a/m4/mysql.m4 b/m4/mysql.m4
new file mode 100644
index 0000000..78de056
--- /dev/null
+++ b/m4/mysql.m4
@@ -0,0 +1,53 @@
+# Configure paths for mysql
+# Nicolas Noble 2002-12-06
+# stolen from Sam Lantinga
+# stolen from Manish Singh
+# stolen back from Frank Belew
+# stolen from Manish Singh
+# Shamelessly stolen from Owen Taylor
+
+dnl AM_PATH_SDL([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
+dnl Test for mysql, and define MYSQL_CFLAGS and MYSQL_LIBS
+dnl
+AC_DEFUN(AM_PATH_MYSQL,
+[dnl
+dnl Get the cflags and libraries from the mysql-config script
+dnl
+AC_ARG_WITH(mysql-prefix,[ --with-mysql-prefix=PFX Prefix where mysql is installed (optional)],
+ mysql_prefix="$withval", mysql_prefix="")
+AC_ARG_WITH(mysql-exec-prefix,[ --with-mysql-exec-prefix=PFX Exec prefix where mysql is installed (optional)],
+ mysql_exec_prefix="$withval", mysql_exec_prefix="")
+
+ if test x$mysql_exec_prefix != x ; then
+ mysql_args="$mysql_args --exec-prefix=$mysql_exec_prefix"
+ if test x${MYSQL_CONFIG+set} != xset ; then
+ MYSQL_CONFIG=$mysql_exec_prefix/bin/mysql_config
+ fi
+ fi
+ if test x$mysql_prefix != x ; then
+ mysql_args="$mysql_args --prefix=$mysql_prefix"
+ if test x${MYSQL_CONFIG+set} != xset ; then
+ MYSQL_CONFIG=$mysql_prefix/bin/mysql_config
+ fi
+ fi
+
+ PATH="$prefix/bin:$prefix/usr/bin:$PATH"
+ AC_PATH_PROG(MYSQL_CONFIG, mysql_config, no, [$PATH])
+ no_mysql=""
+ if test "$MYSQL_CONFIG" = "no" ; then
+ no_mysql=yes
+ else
+ MYSQL_CFLAGS=`$MYSQL_CONFIG $mysqlconf_args --cflags`
+ MYSQL_LIBS=`$MYSQL_CONFIG $mysqlconf_args --libs`
+ fi
+
+ if test "x$no_mysql" = x ; then
+ ifelse([$1], , :, [$1])
+ else
+ MYSQL_CFLAGS=""
+ MYSQL_LIBS=""
+ ifelse([$2], , :, [$2])
+ fi
+ AC_SUBST(MYSQL_CFLAGS)
+ AC_SUBST(MYSQL_LIBS)
+])