[16] | 1 | // |
---|
| 2 | // Case-based reasoner |
---|
| 3 | // |
---|
| 4 | |
---|
| 5 | #include <stdlib.h> |
---|
| 6 | #include <string.h> |
---|
| 7 | #include <stdio.h> |
---|
| 8 | |
---|
| 9 | #include "cbr.h" |
---|
| 10 | |
---|
| 11 | struct cbr_s { |
---|
| 12 | char filename[64]; |
---|
| 13 | char tablename[64]; |
---|
| 14 | char command[2048]; |
---|
| 15 | sqlite3 *db; |
---|
| 16 | unsigned int num_columns; |
---|
| 17 | }; |
---|
| 18 | |
---|
| 19 | int cbr_callback(void *notUsed, int argc, char **argv, char **azColName); |
---|
| 20 | |
---|
| 21 | cbr cbr_create(char * _filename, char * _tablename, char * _cols[], unsigned int _len) |
---|
| 22 | { |
---|
| 23 | cbr _cbr = (cbr) malloc(sizeof(struct cbr_s)); |
---|
| 24 | |
---|
[17] | 25 | // copy filename, tablename |
---|
| 26 | strcpy(_cbr->filename, _filename); |
---|
| 27 | strcpy(_cbr->tablename, _tablename); |
---|
[16] | 28 | |
---|
| 29 | _cbr->db = NULL; |
---|
| 30 | _cbr->num_columns = _len; |
---|
| 31 | |
---|
| 32 | // create table |
---|
| 33 | strcpy(_cbr->command, "CREATE TABLE "); |
---|
| 34 | strcat(_cbr->command, _tablename); |
---|
| 35 | strcat(_cbr->command, "("); |
---|
[17] | 36 | unsigned int i; |
---|
[16] | 37 | for (i=0; i<_len; i++) { |
---|
| 38 | strcat(_cbr->command, _cols[i]); |
---|
| 39 | strcat(_cbr->command, " FLOAT"); |
---|
| 40 | if (i != _len-1) |
---|
| 41 | strcat(_cbr->command, ", "); |
---|
| 42 | } |
---|
| 43 | strcat(_cbr->command, ");"); |
---|
| 44 | printf("command : %s\n", _cbr->command); |
---|
| 45 | |
---|
| 46 | // execute command |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | return _cbr; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | void cbr_free(cbr _cbr) |
---|
| 53 | { |
---|
| 54 | // delete table here |
---|
| 55 | |
---|
| 56 | free(_cbr); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | void cbr_print(cbr _cbr) |
---|
| 60 | { |
---|
| 61 | printf("database %s, table %s:\n", _cbr->filename, _cbr->tablename); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | //static |
---|
| 65 | int cbr_callback(void *notUsed, int argc, char **argv, char **azColName) |
---|
| 66 | { |
---|
| 67 | return 0; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | int cbr_search(cbr _cbr, char *_names[], int * _ops, float *_vals, unsigned int _n, float *_retvals) |
---|
| 71 | { |
---|
| 72 | // set up statement |
---|
| 73 | |
---|
| 74 | char* zErrMsg = NULL; |
---|
| 75 | //sqlite3_exec(_cbr->db, argv[2], callback, NULL, &zErrMsg); |
---|
| 76 | sqlite3_exec(_cbr->db, _cbr->command, cbr_callback, NULL, &zErrMsg); |
---|
| 77 | |
---|
| 78 | return 0; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | int cbr_add_row(cbr _cbr, char *_cols[], float *_vals, unsigned int _len) |
---|
| 82 | { |
---|
| 83 | return 0; |
---|
| 84 | } |
---|
| 85 | |
---|