Changeset 203
- Timestamp:
- 10/29/06 15:29:18 (2 years ago)
- Files:
-
- 06/libkombilo/Makefile (modified) (1 diff)
- 06/libkombilo/cpptest.cc (modified) (1 diff)
- 06/libkombilo/search.cc (modified) (4 diffs)
- 06/libkombilo/search.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
06/libkombilo/Makefile
r196 r203 17 17 g++ -Wall -g -O0 -o cpptest -lsqlite3 -lboost_filesystem cpptest.cc search.cc sgfparser.cc abstractboard.cc 18 18 19 fast: 20 g++ -O3 -o cpptest -lsqlite3 -lboost_filesystem cpptest.cc search.cc sgfparser.cc abstractboard.cc 21 19 22 clean: 20 23 rm search.o abstractboard.o sgfparser.o cpptest 06/libkombilo/cpptest.cc
r200 r203 106 106 107 107 // ------------------- resetFormat ------------------------------------------ 108 printf("reset db\n"); 108 109 gl.resetFormat("pb"); 109 110 vector<string> res = gl.currentEntriesAsStrings(0, 40); 06/libkombilo/search.cc
r202 r203 3340 3340 throw DBError(); 3341 3341 } 3342 rc = sqlite3_busy_timeout(db, 200); 3343 if (rc) throw DBError(); 3344 rc = sqlite3_exec(db, "pragma synchronous = off;", 0, 0, 0); 3345 if (rc) throw DBError(); 3346 rc = sqlite3_exec(db, "pragma cache_size = 700000;", 0, 0, 0); 3347 if (rc) throw DBError(); 3342 3348 3343 3349 rc = sqlite3_exec(db, "create table if not exists db_info ( info text );", 0, 0, 0); … … 3480 3486 // throw DBError(); 3481 3487 // } 3482 rc = sqlite3_busy_timeout(db, 200);3483 if (rc) throw DBError();3484 rc = sqlite3_exec(db, "pragma synchronous = off;", 0, 0, 0);3485 if (rc) throw DBError();3486 rc = sqlite3_exec(db, "pragma cache_size = 300000;", 0, 0, 0);3487 if (rc) throw DBError();3488 3488 rc = sqlite3_exec(db, "begin transaction;", 0, 0, 0); 3489 3489 if (rc) throw DBError(); … … 3674 3674 } 3675 3675 3676 void GameList::tagsearch(int tag) throw(DBError) { 3677 char sql[200]; 3678 3679 if (!tag) return; 3680 if (tag > 0) { 3681 sprintf(sql, "select games.id from games join game_tags on games.id = game_tags.game_id where game_tags.tag_id = %d order by games.id", tag); 3682 } else { 3683 sprintf(sql, "select games.id from games except select games.id from games join game_tags on games.id = game_tags.game_id where game_tags.tag_id = %d order by games.id;", -tag); 3684 } 3685 gisearch(sql, 1); 3686 } 3687 3688 void GameList::setTag(int tag, int start, int end) throw(DBError) { 3689 if (end==0) end = currentList->size(); 3690 if (start>end || end > (int)currentList->size()) return; 3691 int rc = sqlite3_exec(db, "begin transaction", 0, 0, 0); 3692 if (rc != SQLITE_OK) throw DBError(); 3693 for(int i = start; i < end; i++) { 3694 if (getTags(i, tag).size()) continue; 3695 char sql[200]; 3696 sprintf(sql, "insert into game_tags (game_id, tag_id) values (%d, %d)", (*all)[(*currentList)[i].second]->id, tag); 3697 rc = sqlite3_exec(db, sql, 0, 0, 0); 3698 if (rc != SQLITE_OK) throw DBError(); 3699 } 3700 rc = sqlite3_exec(db, "commit", 0, 0, 0); 3701 if (rc != SQLITE_OK) throw DBError(); 3702 } 3703 3704 void GameList::deleteTag(int tag, int i) throw(DBError) { 3705 char sql[200]; 3706 if (i == -1) sprintf(sql, "delete from game_tags where tag_id=%d", tag); 3707 else sprintf(sql, "delete from game_tags where game_id=%d and tag_id=%d", (*all)[(*currentList)[i].second]->id, tag); 3708 int rc = sqlite3_exec(db, sql, 0, 0, 0); 3709 if (rc != SQLITE_OK) throw DBError(); 3710 } 3711 3712 int gettags_callback(void *res, int argc, char **argv, char **azColName) { 3713 if (!argc) return 1; 3714 ((vector<int>*)res)->push_back(atoi(argv[0])); 3715 return 0; 3716 } 3717 3718 vector<int> GameList::getTags(int i, int tag) throw(DBError) { 3719 vector<int> result; 3720 char sql[200]; 3721 if (tag==0) sprintf(sql, "select tag_id from game_tags where game_id=%d", (*all)[(*currentList)[i].second]->id); 3722 else sprintf(sql, "select tag_id from game_tags where game_id=%d and tag_id=%d", (*all)[(*currentList)[i].second]->id, tag); 3723 int rc = sqlite3_exec(db, sql, gettags_callback, &result, 0); 3724 if (rc != SQLITE_OK) throw DBError(); 3725 return result; 3726 } 3727 3676 3728 int gis_callback(void *gl, int argc, char **argv, char **azColName) { 3677 if (!argc) throw DBError();3729 if (!argc) return 1; 3678 3730 ((GameList*)gl)->makeIndexHit(atoi(argv[0]), 0); 3679 3731 return 0; 3680 3732 } 3681 3733 3682 void GameList::gisearch(char* sql ) throw(DBError) {3734 void GameList::gisearch(char* sql, int complete) throw(DBError) { 3683 3735 bool dbWasOpen = false; 3684 3736 if (!db) { … … 3697 3749 if (rc) throw DBError(); 3698 3750 } 3699 string query = "select id from games where "; 3751 string query; 3752 if (!complete) query = "select id from games where "; 3700 3753 query += sql; 3701 query += " order by id"; 3754 if (!complete) query += " order by id"; 3755 // printf("%s\n", query.c_str()); 3702 3756 int rc = sqlite3_exec(db, query.c_str(), gis_callback, this, 0); 3703 3757 if( rc!=SQLITE_OK ) throw DBError(); 06/libkombilo/search.h
r201 r203 576 576 std::vector<GameListEntry* > * all; 577 577 std::vector<std::pair<int,int> > * currentList; // pair of game id and position within all 578 // (usually sorted w.r.t. second 579 // component) 578 // (usually sorted w.r.t. second component) 580 579 std::vector<std::pair<int,int> > * oldList; 581 580 int current; … … 586 585 587 586 // the following methods provide the user interface 587 588 // p_options will be copied by GameList, so the caller has to free the pointer 588 589 GameList(char* DBNAME, std::string ORDERBY="", std::string FORMAT="", ProcessOptions* p_options=0) throw(DBError); 589 // p_options will be copied by GameList, so the caller has to free the pointer 590 590 591 void start_processing(int PROCESSVARIATIONS=-1) throw(DBError); 592 int process(const char* sgf, const char* path, const char* fn, const char* DBTREE = 0) throw(SGFError,DBError); 593 void finalize_processing() throw(DBError); 594 595 // options is copied in the search method (if != 0), so the caller has to free the pointer 591 596 void search(Pattern& pattern, SearchOptions* options = 0) throw(DBError); 592 // options is copied in the search method (if != 0), so the caller has to free the pointer 593 597 char lookupLabel(char x, char y); 598 Continuation lookupContinuation(char x, char y); 599 600 void gisearch(char* sql, int complete=0) throw(DBError); 601 602 void tagsearch(int tag) throw(DBError); 603 void setTag(int tag, int start=0, int end=0) throw(DBError); 604 void deleteTag(int tag, int i = -1) throw(DBError); 605 std::vector<int> getTags(int i, int tag=0) throw(DBError); // note the order of arguments! 606 594 607 void reset(); // reset currentList to all 595 608 void resetFormat(std::string ORDERBY="", std::string FORMAT=""); 596 void gisearch(char* sql) throw(DBError);597 609 int size(); 610 int numHits(); 598 611 std::string resultsStr(GameListEntry* gle); 599 612 std::string currentEntryAsString(int i); … … 601 614 std::string getSGF(int i) throw(DBError); 602 615 std::string getCurrentProperty(int i, std::string tag) throw (DBError); 603 int numHits(); 604 605 void start_processing(int PROCESSVARIATIONS=-1) throw(DBError); 606 int process(const char* sgf, const char* path, const char* fn, const char* DBTREE = 0) throw(SGFError,DBError); 607 void finalize_processing() throw(DBError); 608 616 609 617 // internal methods (called from the algorithm classes) 610 618 ~GameList(); … … 619 627 void makeIndexCandidate(int index, std::vector<Candidate* > *candidates); 620 628 void makeIndexHit(int index, std::vector<Hit* > *hits); 621 char lookupLabel(char x, char y);622 Continuation lookupContinuation(char x, char y);623 629 624 630 private:
