[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 | |
---|
| 25 | // copy filename |
---|
| 26 | unsigned int i=0; |
---|
| 27 | do { |
---|
| 28 | _cbr->filename[i] = _filename[i]; |
---|
| 29 | } while (_filename[i++] != '\0'); |
---|
| 30 | |
---|
| 31 | // copy tablename |
---|
| 32 | i=0; |
---|
| 33 | do { |
---|
| 34 | _cbr->tablename[i] = _tablename[i]; |
---|
| 35 | } while (_tablename[i++] != '\0'); |
---|
| 36 | |
---|
| 37 | _cbr->db = NULL; |
---|
| 38 | _cbr->num_columns = _len; |
---|
| 39 | |
---|
| 40 | // create table |
---|
| 41 | strcpy(_cbr->command, "CREATE TABLE "); |
---|
| 42 | strcat(_cbr->command, _tablename); |
---|
| 43 | strcat(_cbr->command, "("); |
---|
| 44 | for (i=0; i<_len; i++) { |
---|
| 45 | strcat(_cbr->command, _cols[i]); |
---|
| 46 | strcat(_cbr->command, " FLOAT"); |
---|
| 47 | if (i != _len-1) |
---|
| 48 | strcat(_cbr->command, ", "); |
---|
| 49 | } |
---|
| 50 | strcat(_cbr->command, ");"); |
---|
| 51 | printf("command : %s\n", _cbr->command); |
---|
| 52 | |
---|
| 53 | // execute command |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | return _cbr; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | void cbr_free(cbr _cbr) |
---|
| 60 | { |
---|
| 61 | // delete table here |
---|
| 62 | |
---|
| 63 | free(_cbr); |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | void cbr_print(cbr _cbr) |
---|
| 67 | { |
---|
| 68 | printf("database %s, table %s:\n", _cbr->filename, _cbr->tablename); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | //static |
---|
| 72 | int cbr_callback(void *notUsed, int argc, char **argv, char **azColName) |
---|
| 73 | { |
---|
| 74 | return 0; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | int cbr_search(cbr _cbr, char *_names[], int * _ops, float *_vals, unsigned int _n, float *_retvals) |
---|
| 78 | { |
---|
| 79 | // set up statement |
---|
| 80 | |
---|
| 81 | char* zErrMsg = NULL; |
---|
| 82 | //sqlite3_exec(_cbr->db, argv[2], callback, NULL, &zErrMsg); |
---|
| 83 | sqlite3_exec(_cbr->db, _cbr->command, cbr_callback, NULL, &zErrMsg); |
---|
| 84 | |
---|
| 85 | return 0; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | int cbr_add_row(cbr _cbr, char *_cols[], float *_vals, unsigned int _len) |
---|
| 89 | { |
---|
| 90 | return 0; |
---|
| 91 | } |
---|
| 92 | |
---|