Refine code
authorPeng Huang <shawn.p.huang@gmail.com>
Sat, 10 Apr 2010 12:16:24 +0000 (20:16 +0800)
committerPeng Huang <shawn.p.huang@gmail.com>
Sat, 10 Apr 2010 12:29:16 +0000 (20:29 +0800)
src/Database.cc
src/Phrase.h

index 1332791..c7e1823 100644 (file)
@@ -85,15 +85,23 @@ public:
     }
 
     gboolean step (void) {
-        return sqlite3_step (m_stmt) == SQLITE_ROW;
+        switch (sqlite3_step (m_stmt)) {
+        case SQLITE_ROW:
+            return TRUE;
+        case SQLITE_DONE:
+            return FALSE;
+        default:
+            g_warning ("sqlites step error!");
+            return FALSE;
+        }
     }
 
-    const gchar *columnText (guint i) {
-        return (const gchar *) sqlite3_column_text (m_stmt, i);
+    const gchar *columnText (guint col) {
+        return (const gchar *) sqlite3_column_text (m_stmt, col);
     }
 
-    gint columnInt (guint i) {
-        return sqlite3_column_int (m_stmt, i);
+    gint columnInt (guint col) {
+        return sqlite3_column_int (m_stmt, col);
     }
 
 private:
@@ -148,6 +156,7 @@ Query::fill (PhraseArray &phrases, gint count)
                 phrase.pinyin_id[i][0] = m_stmt->columnInt (column++);
                 phrase.pinyin_id[i][1] = m_stmt->columnInt (column++);
             }
+
             phrases.push_back (phrase);
             row ++;
             if (G_UNLIKELY (row == count)) {
index 20de45d..02f091f 100644 (file)
@@ -7,10 +7,9 @@
 
 namespace PY {
 
-
 typedef struct _Phrase Phrase;
 struct _Phrase {
-    gchar phrase[(MAX_PHRASE_LEN + 1) * MAX_UTF8_LEN];
+    gchar phrase[MAX_UTF8_LEN * (MAX_PHRASE_LEN + 1)];
     guint  freq;
     guint  user_freq;
     guint  pinyin_id[MAX_PHRASE_LEN][2];