Show
Ignore:
Timestamp:
04/03/09 13:05:41 (15 years ago)
Author:
trnewman
Message:

Added a loop in the demo to actually adapt.

Added simple adaptation functionality and proper db querying in the CE.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • vtcross/trunk/src/cognitive_engines/cbr.c

    r228 r230  
    222222    } 
    223223 
    224     printf("search command: %s\n", _cbr->command); 
     224    //printf("search command: %s\n", _cbr->command); 
    225225 
    226226    //ExecuteCommand(_cbr); 
     
    235235} 
    236236 
     237 
     238// update a row  
     239int cbr_update(cbr _cbr, char *_where[], char*_set[], float *_wherevals, float *_setvals,  
     240                unsigned int _wherelen, unsigned int _setlen) 
     241{ 
     242    unsigned int i; 
     243     
     244    // generate command 
     245    //printf("%s\n", _cbr->command); 
     246    strcpy(_cbr->command, "UPDATE "); 
     247    strcat(_cbr->command, _cbr->tablename); 
     248     
     249    strcat(_cbr->command, " SET "); 
     250    for (i=0; i<_setlen; i++) { 
     251        strcat(_cbr->command, _set[i]); 
     252        strcat(_cbr->command, " = "); 
     253        sprintf(_cbr->command, "%s%f", _cbr->command, _setvals[i]); 
     254        strcat(_cbr->command, "  "); 
     255        if (i != _setlen-1) // not last entry 
     256            strcat(_cbr->command, ", "); 
     257    } 
     258    strcat(_cbr->command, " WHERE "); 
     259 
     260    for (i=0; i<_wherelen; i++) { 
     261        strcat(_cbr->command, _where[i]); 
     262        strcat(_cbr->command, " = "); 
     263        sprintf(_cbr->command, "%s%f", _cbr->command, _wherevals[i]); 
     264        strcat(_cbr->command, "  "); 
     265        if (i != _wherelen-1) // not last entry 
     266            strcat(_cbr->command, "AND "); 
     267    } 
     268    strcat(_cbr->command, ";"); 
     269     
     270    //printf("search command: %s\n", _cbr->command); 
     271    // execute add command 
     272    ExecuteCommand(_cbr); 
     273 
     274    return 0; 
     275} 
    237276 
    238277// cbr add a row 
     
    264303    strcat(_cbr->command, ");"); 
    265304     
     305    //printf("search command: %s\n", _cbr->command); 
    266306    // execute add command 
    267307    ExecuteCommand(_cbr);