[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: SQLite patch for smsd
From: |
Santeri Toikka |
Subject: |
Re: SQLite patch for smsd |
Date: |
Tue, 06 Apr 2010 18:36:13 +0300 |
User-agent: |
Thunderbird 2.0.0.24 (X11/20100317) |
Pawel Kot wrote:
On the first sight it looks good. Just two minor issues:
- use /* and not // as the comment
- watch out non ascii characters present in your patch -- they should
be utf-8 encoded
I'll be more precise on this matter.
- is choosing sqlite3 definite? isn't it possible to make it generic?
if sqlite3 is for some reason let's name it sqlite3 and not sqlite
In my, opinion it is. SQLite3 introduces more subtle manners to deal
with concurrency which is required.
- this:
+ SQLITE_LIBS="-L/usr/lib -lsqlite3"
+ SQLITE_CFLAGS="-I/usr/include"
is not correct, that should be detected from some pkg-config or
whatever; hardcoding won't work
I didn't figure out how to do this. Postgre and MySQL packages deliver
little helper applications, but SQLite doesn't. Therefore only basic
header check is done here.
Auto-everything is a mind bobling set of scripts that I have not studied
in great detail. This is just nasty cut&paste from other parts of the
configure.in file.
I hope you tested it in working.
Of course :)
Patch included. It changes format of the comments and drops hard coded
paths from compile flags.
cheers,
--
Santeri Toikka
>From 095b056a291afad1d2470d83ca9ce2bc1003d192 Mon Sep 17 00:00:00 2001
From: Santeri Toikka <address@hidden>
Date: Tue, 6 Apr 2010 18:23:53 +0300
Subject: [PATCH 3/3] Proposed changes to smsd SQLite module
---
configure.in | 6 ++----
smsd/db.h | 12 ++++++++----
smsd/sqlite.c | 15 +++++++++------
3 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/configure.in b/configure.in
index 4e33bd3..f6e69f4 100644
--- a/configure.in
+++ b/configure.in
@@ -752,7 +752,6 @@ fi
AM_CONDITIONAL(HAVE_POSTGRES, test "x$have_postgres" = "xyes")
-dnl snip
AC_ARG_ENABLE(sqlite,
AC_HELP_STRING([--disable-sqlite],
[disable SQLite support (default is autodetected)]),
@@ -762,13 +761,12 @@ have_sqlite=no
AC_CHECK_HEADERS(sqlite3.h, have_sqlite=yes, have_sqlite=no)
if test x$enable_sqlite != xno; then
have_sqlite=yes
- SQLITE_LIBS="-L/usr/lib -lsqlite3"
- SQLITE_CFLAGS="-I/usr/include"
+ SQLITE_LIBS="-lsqlite3"
+ SQLITE_CFLAGS=""
AC_SUBST(SQLITE_LIBS)
AC_SUBST(SQLITE_CFLAGS)
fi
AM_CONDITIONAL(HAVE_SQLITE, test "x$have_sqlite" = "xyes")
-dnl snip
AC_ARG_ENABLE(mysql,
AC_HELP_STRING([--disable-mysql],
diff --git a/smsd/db.h b/smsd/db.h
index 9fc8438..d9dd3e7 100644
--- a/smsd/db.h
+++ b/smsd/db.h
@@ -34,17 +34,21 @@
#include "smsd.h"
#include "gnokii.h"
-// Close all connections
+/* Close all connections
+ */
GNOKII_API void (*DB_Bye) (void);
-// Initialize connection
+/* Initialize connection
+ */
GNOKII_API gint (*DB_ConnectInbox) (const DBConfig);
GNOKII_API gint (*DB_ConnectOutbox) (const DBConfig);
-// Write a new message to inbox
+/* Write a new message to inbox
+ */
GNOKII_API gint (*DB_InsertSMS) (const gn_sms * const, const gchar * const);
-// Send messages from outbox
+/* Send messages from outbox
+ */
GNOKII_API void (*DB_Look) (const gchar * const);
#endif
diff --git a/smsd/sqlite.c b/smsd/sqlite.c
index f99d3be..c84a836 100644
--- a/smsd/sqlite.c
+++ b/smsd/sqlite.c
@@ -110,7 +110,6 @@ GNOKII_API gint DB_InsertSMS(const gn_sms * const data,
const gchar * const phon
g_string_free(text, TRUE);
g_string_free(phnStr, TRUE);
- // -1: read to end of buffer, NULL: ignore tail
error = sqlite3_prepare_v2(ppDbInbox, buf->str, -1, &stmt, NULL);
if (error != SQLITE_OK) {
g_print(_("%d: Parsing query %s failed!"), __LINE__, buf->str);
@@ -118,13 +117,14 @@ GNOKII_API gint DB_InsertSMS(const gn_sms * const data,
const gchar * const phon
return 1;
}
- // run query
+ /* run query
+ */
int i;
for (i = 0; i < 6; i++) {
error = sqlite3_step(stmt);
if (error = SQLITE_DONE)
break;
-
+
sleep(1);
sqlite3_reset(stmt);
}
@@ -166,7 +166,8 @@ GNOKII_API void DB_Look(const gchar * const phone) {
sqlite3_exec(ppDbOutbox, "BEGIN TRANSACTION;", NULL, NULL, NULL);
- // poll for outgoing messages
+ /* poll for outgoing messages
+ */
buf = g_string_sized_new(256);
g_string_printf(buf, "SELECT id, number, text, dreport FROM outbox \
WHERE processed=0 \
@@ -222,7 +223,8 @@ GNOKII_API void DB_Look(const gchar * const phone) {
} while ((error == GN_ERR_TIMEOUT || error == GN_ERR_FAILED) &&
numError++ < 3);
- // mark sended
+ /* mark sended
+ */
g_string_printf(buf, "UPDATE outbox SET processed=1, error='%d', \
processed_date=%s \
WHERE id=%d",
@@ -233,7 +235,8 @@ GNOKII_API void DB_Look(const gchar * const phone) {
ret1 = sqlite3_step(stmt);
}
- // rollback if found any errors
+ /* rollback if found any errors
+ */
if (ret1 != SQLITE_DONE) {
g_print(_("%d: SELECT FROM outbox command failed.\n"), __LINE__);
g_print(_("Error: %s\n"), sqlite3_errmsg(ppDbOutbox));
--
1.6.3.3