Browse code

table_version returns version 0 if there is no row for the given table is found in table "version".

Jan Janak authored on 22/01/2004 22:28:36
Showing 2 changed files
... ...
@@ -96,6 +96,7 @@ int bind_dbmod(char* mod)
96 96
 
97 97
 /*
98 98
  * Get version of a table
99
+ * If there is no row for the given table, return version 0
99 100
  */
100 101
 int table_version(db_con_t* connection, const str* table)
101 102
 {
... ...
@@ -127,8 +128,13 @@ int table_version(db_con_t* connection, const str* table)
127 128
 		return -1;
128 129
 	}
129 130
 
131
+	if (RES_ROW_N(res) == 0) {
132
+		DBG("table_version(): No row for table %s found\n", table->len, ZSW(table->s));
133
+		return 0;
134
+	}
135
+
130 136
 	if (RES_ROW_N(res) != 1) {
131
-		LOG(L_ERR, "table_version(): Invalid number of rows received: %d, %.*s\n", RES_ROW_N(res), table->len, table->s);
137
+		LOG(L_ERR, "table_version(): Invalid number of rows received: %d, %.*s\n", RES_ROW_N(res), table->len, ZSW(table->s));
132 138
 		db_free_query(connection, res);
133 139
 		return -1;
134 140
 	}
... ...
@@ -165,7 +165,9 @@ int bind_dbmod(char* mod);
165 165
 
166 166
 
167 167
 /*
168
- * Get version of a table
168
+ * Get the version of the given table. If there is
169
+ * no row for the table then the function returns
170
+ * version 0. -1 is returned on error.
169 171
  */
170 172
 int table_version(db_con_t* con, const str* table);
171 173