Changeset 211
- Timestamp:
- 01/13/07 14:36:34 (1 year ago)
- Files:
-
- 06/libkombilo/search.cpp (modified) (5 diffs)
- 06/libkombilo/search.h (modified) (1 diff)
- 06/libkombilo/testsearch.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
06/libkombilo/search.cpp
r210 r211 514 514 // printf("%d, %d, %d, %d, %d, %d, %d\n", f, newSizeX, newSizeY, newLeft, newRight, newTop, newBottom); 515 515 char* newInitialPos = new char[pattern.sizeX*pattern.sizeY]; 516 unsignedi=0;516 int i=0; 517 517 for(i=0; i<pattern.sizeX; i++) { 518 518 for(int j=0; j<pattern.sizeY; j++) { … … 3563 3563 if (currentList) delete currentList; 3564 3564 if (oldList) delete oldList; 3565 for( int i=0; i<20*boardsizes.size(); i++)3565 for(unsigned int i=0; i<20*boardsizes.size(); i++) 3566 3566 if (algo_ps[i]) delete algo_ps[i]; 3567 3567 if (db) sqlite3_close(db); … … 3757 3757 } 3758 3758 3759 void GameList::sigsearch(char* sig) throw(DBError) { 3760 if (start_sorted() == 0) { 3761 string query = "select id from algo_signature_19 where signature = ? order by id"; 3762 // int rc = sqlite3_exec(db, query.c_str(), sigs_callback, this, 0); 3763 sqlite3_stmt *ppStmt=0; 3764 int rc = sqlite3_prepare(db, query.c_str(), -1, &ppStmt, 0); 3765 if (rc != SQLITE_OK || ppStmt==0) throw DBError(); 3766 rc = sqlite3_bind_blob(ppStmt, 1, sig, 12, SQLITE_TRANSIENT); 3767 if (rc != SQLITE_OK || ppStmt==0) throw DBError(); 3768 do { 3769 rc = sqlite3_step(ppStmt); 3770 if (rc != SQLITE_DONE && rc != SQLITE_ROW) throw DBError(); 3771 if (rc == SQLITE_ROW) { 3772 makeIndexHit(sqlite3_column_int(ppStmt, 0), 0); 3773 } 3774 } while (rc == SQLITE_ROW); 3775 rc = sqlite3_finalize(ppStmt); 3776 if (rc != SQLITE_OK) throw DBError(); 3777 3778 end_sorted(); 3779 } 3780 } 3781 3759 3782 int gis_callback(void *gl, int argc, char **argv, char **azColName) { 3760 3783 if (!argc) return 1; … … 3853 3876 } 3854 3877 3855 string GameList::getSGF(int i) throw(DBError) {3856 if (!p_op->sgfInDB) return "";3857 return getCurrentProperty(i, "sgf");3858 }3859 3860 3878 int getpropcallback(void *s, int argc, char **argv, char **azColName) { 3861 3879 char** prop = (char**)s; … … 3865 3883 } 3866 3884 return 0; 3885 } 3886 3887 string GameList::getSignature(int i) throw(DBError) { 3888 if (i < 0 || i >= (int)currentList->size()) { 3889 // printf("index out of range\n"); 3890 return ""; 3891 } 3892 int index = (*all)[(*currentList)[i].second]->id; 3893 // int rc = sqlite3_open(dbname, &db); 3894 // if (rc) { 3895 // sqlite3_close(db); 3896 // db = 0; 3897 // throw DBError(); 3898 // } 3899 char* prop = 0; 3900 char sql[200]; 3901 sprintf(sql, "select signature from algo_signature_19 where id = %d;", index); 3902 // printf("%s\n", sql); 3903 int rc = sqlite3_exec(db, sql, getpropcallback, &prop, 0); 3904 if (rc != SQLITE_OK) throw DBError(); 3905 // sqlite3_close(db); 3906 // db = 0; 3907 3908 if (!prop) return ""; 3909 string prop_str(prop); 3910 delete [] prop; 3911 return prop_str; 3912 } 3913 3914 string GameList::getSGF(int i) throw(DBError) { 3915 if (!p_op->sgfInDB) return ""; 3916 return getCurrentProperty(i, "sgf"); 3867 3917 } 3868 3918 06/libkombilo/search.h
r208 r211 602 602 Continuation lookupContinuation(char x, char y); 603 603 604 // ------- signature search --------------------------------------------------- 605 void sigsearch(char* sig) throw(DBError); 606 std::string getSignature(int i) throw(DBError); 607 604 608 // ------- game info search --------------------------------------------------- 605 609 void gisearch(char* sql, int complete=0) throw(DBError); 06/libkombilo/testsearch.py
r206 r211 62 62 print 'Player %d: %s' % (i, gl.plEntry(i)) 63 63 64 gl.reset() 65 gl.sigsearch('cfcgjbbeckjc') 66 print gl.size(), 'games with signature cfcgjbbeckjc.' 67 gl.sigsearch('aaaaaaaaaaaa') 68 print gl.size(), 'games with signature aaaaaaaaaaaa.' 69 gl.reset() 70 gl.sigsearch('dfcnfmepgkjo') 71 print gl.size(), 'games with signature dfcnfmepgkjo:' 72 print gl.currentEntryAsString(0) 73 print 'signature of game 0: ', gl.getSignature(0) 74 75
