Changeset 201
- Timestamp:
- 10/15/06 22:15:15 (2 years ago)
- Files:
-
- 06/libkombilo/search.cc (modified) (2 diffs)
- 06/libkombilo/search.h (modified) (1 diff)
- 06/libkombilo/testsearch.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
06/libkombilo/search.cc
r200 r201 3768 3768 } 3769 3769 3770 int getsgfcallback(void *s, int argc, char **argv, char **azColName) { 3771 char** sgf = (char**)s; 3770 string GameList::getSGF(int i) throw(DBError) { 3771 if (!p_op->sgfInDB) return ""; 3772 return getCurrentProperty(i, "sgf"); 3773 } 3774 3775 int getpropcallback(void *s, int argc, char **argv, char **azColName) { 3776 char** prop = (char**)s; 3772 3777 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]); 3775 3780 } 3776 3781 return 0; 3777 3782 } 3778 3783 3779 string GameList::getSGF(int i) throw(DBError) { 3780 if (!p_op->sgfInDB) { 3781 // printf("not in db\n"); 3782 return ""; 3783 } 3784 string GameList::getCurrentProperty(int i, string tag) throw(DBError) { 3784 3785 if (i < 0 || i >= (int)currentList->size()) { 3785 3786 // printf("index out of range\n"); 3786 3787 return ""; 3787 3788 } 3788 int index = (* currentList)[i].second;3789 int index = (*all)[(*currentList)[i].second]->id; 3789 3790 // int rc = sqlite3_open(dbname, &db); 3790 3791 // if (rc) { … … 3793 3794 // throw DBError(); 3794 3795 // } 3795 char* sgf= 0;3796 char* prop = 0; 3796 3797 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); 3798 3799 // printf("%s\n", sql); 3799 int rc = sqlite3_exec(db, sql, get sgfcallback, &sgf, 0);3800 int rc = sqlite3_exec(db, sql, getpropcallback, &prop, 0); 3800 3801 if (rc != SQLITE_OK) throw DBError(); 3801 3802 // sqlite3_close(db); 3802 3803 // db = 0; 3803 3804 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; 3808 3809 } 3809 3810 06/libkombilo/search.h
r200 r201 600 600 std::vector<std::string> currentEntriesAsStrings(int start=0, int end=0); 601 601 std::string getSGF(int i) throw(DBError); 602 std::string getCurrentProperty(int i, std::string tag) throw (DBError); 602 603 int numHits(); 603 604 06/libkombilo/testsearch.py
r200 r201 7 7 8 8 start = time.time() 9 gl = GameList('t1.db') 9 gl = GameList('t1.db', 'PB') 10 end = time.time() 10 11 print gl.size(), 'games in the database' 11 12 gl.gisearch("pw = 'Cho Chikun'") 12 end = time.time()13 13 print gl.size(), 'games in the database' 14 14 print 'This search took %.2f seconds.' % (end - start) … … 19 19 gl.search(p, SearchOptions()) 20 20 end = time.time() 21 print '\n'.join(gl.currentEntriesAsStrings()) 21 for i in range(gl.size()): 22 print gl.currentEntryAsString(i) 23 print gl.getCurrentProperty(i, 'EV') 24 # print '\n'.join(gl.currentEntriesAsStrings()) 22 25 print gl.size(), 'games, ', gl.numHits(), 'hits.' 23 26 print 'Search pattern:' … … 48 51 print 'This search took %.2f seconds.' % (end - start) 49 52 53 print gl.currentEntryAsString(gl.size()-1) 54 print gl.getCurrentProperty(gl.size()-1, 'PW'), gl.getSGF(gl.size()-1) 50 55 gl.reset() 51 print 'SGF of game 122'52 print gl.getSGF(123)53 56
