Changeset 201

Show
Ignore:
Timestamp:
10/15/06 22:15:15 (2 years ago)
Author:
ug
Message:

getCurrentProperty method to query the db. Yet more bug fixes.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 06/libkombilo/search.cc

    r200 r201  
    37683768} 
    37693769 
    3770 int getsgfcallback(void *s, int argc, char **argv, char **azColName) { 
    3771   char** sgf = (char**)s; 
     3770string GameList::getSGF(int i) throw(DBError) { 
     3771  if (!p_op->sgfInDB) return ""; 
     3772  return getCurrentProperty(i, "sgf"); 
     3773
     3774 
     3775int getpropcallback(void *s, int argc, char **argv, char **azColName) { 
     3776  char** prop = (char**)s; 
    37723777  if (argc && argv[0]) { 
    3773     *sgf = new char[strlen(argv[0])+1]; 
    3774     strcpy(*sgf, argv[0]); 
     3778    *prop = new char[strlen(argv[0])+1]; 
     3779    strcpy(*prop, argv[0]); 
    37753780  } 
    37763781  return 0; 
    37773782} 
    37783783 
    3779 string GameList::getSGF(int i) throw(DBError) { 
    3780   if (!p_op->sgfInDB) { 
    3781     // printf("not in db\n"); 
    3782     return ""; 
    3783   } 
     3784string GameList::getCurrentProperty(int i, string tag) throw(DBError) { 
    37843785  if (i < 0 || i >= (int)currentList->size()) { 
    37853786    // printf("index out of range\n"); 
    37863787    return ""; 
    37873788  } 
    3788   int index = (*currentList)[i].second; 
     3789  int index = (*all)[(*currentList)[i].second]->id; 
    37893790  // int rc = sqlite3_open(dbname, &db);  
    37903791  // if (rc) { 
     
    37933794  //   throw DBError(); 
    37943795  // } 
    3795   char* sgf = 0; 
     3796  char* prop = 0; 
    37963797  char sql[200]; 
    3797   sprintf(sql, "select sgf from games where id = %d;", index+1); 
     3798  sprintf(sql, "select %s from games where id = %d;", tag.c_str(), index); 
    37983799  // printf("%s\n", sql); 
    3799   int rc = sqlite3_exec(db, sql, getsgfcallback, &sgf, 0); 
     3800  int rc = sqlite3_exec(db, sql, getpropcallback, &prop, 0); 
    38003801  if (rc != SQLITE_OK) throw DBError(); 
    38013802  // sqlite3_close(db); 
    38023803  // db = 0; 
    38033804 
    3804   if (!sgf) return ""; 
    3805   string sgf_str(sgf); 
    3806   delete [] sgf
    3807   return sgf_str; 
     3805  if (!prop) return ""; 
     3806  string prop_str(prop); 
     3807  delete [] prop
     3808  return prop_str; 
    38083809} 
    38093810 
  • 06/libkombilo/search.h

    r200 r201  
    600600    std::vector<std::string> currentEntriesAsStrings(int start=0, int end=0); 
    601601    std::string getSGF(int i) throw(DBError); 
     602    std::string getCurrentProperty(int i, std::string tag) throw (DBError); 
    602603    int numHits(); 
    603604 
  • 06/libkombilo/testsearch.py

    r200 r201  
    77 
    88start = time.time() 
    9 gl = GameList('t1.db') 
     9gl = GameList('t1.db', 'PB') 
     10end = time.time() 
    1011print gl.size(), 'games in the database' 
    1112gl.gisearch("pw = 'Cho Chikun'") 
    12 end = time.time() 
    1313print gl.size(), 'games in the database' 
    1414print 'This search took %.2f seconds.' % (end - start) 
     
    1919gl.search(p, SearchOptions()) 
    2020end = time.time() 
    21 print '\n'.join(gl.currentEntriesAsStrings()) 
     21for i in range(gl.size()): 
     22    print gl.currentEntryAsString(i) 
     23    print gl.getCurrentProperty(i, 'EV') 
     24# print '\n'.join(gl.currentEntriesAsStrings()) 
    2225print gl.size(), 'games, ', gl.numHits(), 'hits.' 
    2326print 'Search pattern:' 
     
    4851print 'This search took %.2f seconds.' % (end - start) 
    4952 
     53print gl.currentEntryAsString(gl.size()-1) 
     54print gl.getCurrentProperty(gl.size()-1, 'PW'),  gl.getSGF(gl.size()-1) 
    5055gl.reset() 
    51 print 'SGF of game 122' 
    52 print gl.getSGF(123) 
    5356