Subversion Repositories MLServ

Rev

Rev 7 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7 Rev 9
Line 1... Line 1...
1
/* $Id: db.c 7 2024-09-25 00:56:55Z nishi $ */
1
/* $Id: db.c 9 2024-09-25 01:17:09Z nishi $ */
2
 
2
 
3
#include "cm_db.h"
3
#include "cm_db.h"
4
 
4
 
5
#include <sqlite3.h>
5
#include <sqlite3.h>
6
 
6
 
7
#include <stddef.h>
7
#include <stddef.h>
-
 
8
#include <stdlib.h>
-
 
9
#include <stdio.h>
-
 
10
 
-
 
11
#include "cm_string.h"
8
 
12
 
9
sqlite3* cm_db_init(void) {
13
sqlite3* cm_db_init(void) {
10
	int ret;
14
	int ret;
11
	sqlite3* sql;
15
	sqlite3* sql;
12
	ret = sqlite3_open(DB_PATH, &sql);
16
	ret = sqlite3_open(DB_PATH, &sql);
Line 29... Line 33...
29
		return NULL;
33
		return NULL;
30
	}
34
	}
31
	return sql;
35
	return sql;
32
}
36
}
33
 
37
 
-
 
38
int list(void* param, int ncol, char** row, char** col) {
-
 
39
	char** old = *(char***)param;
-
 
40
	int i;
-
 
41
	for(i = 0; old[i] != NULL; i++)
-
 
42
		;
-
 
43
	*(char***)param = malloc(sizeof(*old) * (i + 3));
-
 
44
	for(i = 0; old[i] != NULL; i++) {
-
 
45
		(*(char***)param)[i] = old[i];
-
 
46
	}
-
 
47
	(*(char***)param)[i] = cm_strdup(row[0]);
-
 
48
	(*(char***)param)[i + 1] = cm_strdup(row[1]);
-
 
49
	(*(char***)param)[i + 2] = NULL;
-
 
50
	free(old);
-
 
51
	return 0;
-
 
52
}
-
 
53
 
34
char** cm_list_ml(sqlite3* sql) { return NULL; }
54
char** cm_list_ml(sqlite3* sql) {
-
 
55
	char** listvar = malloc(sizeof(*list));
-
 
56
	listvar[0] = NULL;
-
 
57
	int ret = sqlite3_exec(sql, "select * from lists", list, &listvar, NULL);
-
 
58
	if(ret != SQLITE_OK) {
-
 
59
		int i;
-
 
60
		for(i = 0; listvar[i] != NULL; i++) free(listvar[i]);
-
 
61
		free(listvar);
-
 
62
	}
-
 
63
	return listvar;
-
 
64
}