Forráskód Böngészése

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

Jan Janak 21 éve
szülő
commit
53acfdc439
2 módosított fájl, 10 hozzáadás és 2 törlés
  1. 7 1
      db/db.c
  2. 3 1
      db/db.h

+ 7 - 1
db/db.c

@@ -96,6 +96,7 @@ int bind_dbmod(char* mod)
 
 /*
  * Get version of a table
+ * If there is no row for the given table, return version 0
  */
 int table_version(db_con_t* connection, const str* table)
 {
@@ -127,8 +128,13 @@ int table_version(db_con_t* connection, const str* table)
 		return -1;
 	}
 
+	if (RES_ROW_N(res) == 0) {
+		DBG("table_version(): No row for table %s found\n", table->len, ZSW(table->s));
+		return 0;
+	}
+
 	if (RES_ROW_N(res) != 1) {
-		LOG(L_ERR, "table_version(): Invalid number of rows received: %d, %.*s\n", RES_ROW_N(res), table->len, table->s);
+		LOG(L_ERR, "table_version(): Invalid number of rows received: %d, %.*s\n", RES_ROW_N(res), table->len, ZSW(table->s));
 		db_free_query(connection, res);
 		return -1;
 	}

+ 3 - 1
db/db.h

@@ -165,7 +165,9 @@ int bind_dbmod(char* mod);
 
 
 /*
- * Get version of a table
+ * Get the version of the given table. If there is
+ * no row for the table then the function returns
+ * version 0. -1 is returned on error.
  */
 int table_version(db_con_t* con, const str* table);