Changeset 15601 for gsdl/trunk/lib/sqliteclass.cpp
- Timestamp:
- 2008-05-20T15:58:55+12:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gsdl/trunk/lib/sqliteclass.cpp
r15599 r15601 25 25 26 26 #include "sqliteclass.h" 27 28 29 #define SQLITE_MAX_RETRIES 8 27 30 28 31 … … 124 127 return g_EmptyText; 125 128 } 129 130 131 // sqlexec simply executes the given sql statement - it doesn't obtain a 132 // result set - returns true if the sql statement was executed successfully 133 // logerrors may be set to false to prevent this method from logging an 134 // error if it fails - this is useful in some circumstances when we execute 135 // an sql command specifically to see if it fails (e.g. when testing if a 136 // table exists in the db) 137 bool sqliteclass::sqlexec(const text_t &sql_cmd, bool logerrors) 138 { 139 char *sql_cmd_cstr = sql_cmd.getcstr(); 140 141 int rv = 0; 142 int tries = 0; 143 while ((rv = sqlite3_exec(sqlitefile, sql_cmd_cstr, NULL, NULL, NULL)) == SQLITE_BUSY) 144 { 145 sleep(1000); 146 tries++; 147 if (tries > SQLITE_MAX_RETRIES) 148 { 149 outconvertclass text_t2ascii; 150 (*logout) << text_t2ascii << "max_retries exceeded for sql query: " << sql_cmd << "\n"; 151 break; 152 } 153 } 154 155 delete[] sql_cmd_cstr; 156 157 if (rv == SQLITE_OK) return true; 158 159 if (logerrors) 160 { 161 outconvertclass text_t2ascii; 162 (*logout) << text_t2ascii << "Error executing sql statement: " << sql_cmd << "\n"; 163 } 164 165 return false; 166 } 167 168 169 // sleep for the given number of milliseconds 170 void sleep(int m) 171 { 172 #ifdef __WIN32__ 173 Sleep(m); 174 #else 175 usleep(m); 176 #endif 177 }
Note:
See TracChangeset
for help on using the changeset viewer.