Browse code

- table_version function -- the function returns version of given database table

Jan Janak authored on 28/11/2003 23:47:50
Showing 2 changed files
... ...
@@ -27,8 +27,10 @@
27 27
 
28 28
 
29 29
 #include "db.h"
30
+#include "../dprint.h"
30 31
 #include "../sr_module.h"
31 32
 #include "../mem/mem.h"
33
+#include "../str.h"
32 34
 
33 35
 db_func_t dbf;
34 36
 
... ...
@@ -90,3 +92,48 @@ int bind_dbmod(char* mod)
90 92
 	if (tmp != mod) pkg_free(tmp);
91 93
 	return -1;
92 94
 }
95
+
96
+
97
+/*
98
+ * Get version of a table
99
+ */
100
+int table_version(db_con_t* connection, const str* table)
101
+{
102
+	db_key_t key[1], col[1];
103
+	db_val_t val[1];
104
+	db_res_t* res;
105
+	int ret;
106
+
107
+	if (!connection || !table) {
108
+		LOG(L_ERR, "table_version(): Invalid parameter value\n");
109
+		return -1;
110
+	}
111
+
112
+	if (db_use_table(connection, VERSION_TABLE) < 0) {
113
+		LOG(L_ERR, "table_version(): Error while changing table\n");
114
+		return -1;
115
+	}
116
+
117
+	key[0] = TABLENAME_COLUMN;
118
+
119
+	VAL_TYPE(val) = DB_STR;
120
+	VAL_NULL(val) = 0;
121
+	VAL_STR(val) = *table;
122
+	
123
+	col[0] = VERSION_COLUMN;
124
+	
125
+	if (db_query(connection, key, 0, val, col, 1, 1, 0, &res) < 0) {
126
+		LOG(L_ERR, "table_version(): Error in db_query\n");
127
+		return -1;
128
+	}
129
+
130
+	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);
132
+		db_free_query(connection, res);
133
+		return -1;
134
+	}
135
+
136
+	ret = VAL_INT(ROW_VALUES(RES_ROWS(res)));
137
+	db_free_query(connection, res);
138
+	return ret;
139
+}
... ...
@@ -162,6 +162,12 @@ extern db_func_t dbf;
162 162
 
163 163
 
164 164
 int bind_dbmod(char* mod);
165
- 
165
+
166
+
167
+/*
168
+ * Get version of a table
169
+ */
170
+int table_version(db_con_t* con, const str* table);
171
+
166 172
 
167 173
 #endif /* DB_H */