| 131 | } |
| 132 | |
| 133 | bool SqQuery::Execute() |
| 134 | { |
| 135 | int rc; |
| 136 | |
| 137 | /* If we don't have a result set and we have a column count, |
| 138 | * create a result set pre-emptively. This is in case there |
| 139 | * are no rows in the upcoming result set. |
| 140 | */ |
| 141 | if (!m_pResults && m_ColCount) |
| 142 | { |
| 143 | m_pResults = new SqResults(this); |
| 144 | } |
| 145 | |
| 146 | /* If we've got results, throw them away */ |
| 147 | if (m_pResults) |
| 148 | { |
| 149 | m_pResults->ResetResultCount(); |
| 150 | } |
| 151 | |
| 152 | /* Fetch each row, if any */ |
| 153 | while ((rc = sqlite3_step(m_pStmt)) == SQLITE_ROW) |
| 154 | { |
| 155 | /* This should NEVER happen but we're being safe. */ |
| 156 | if (!m_pResults) |
| 157 | { |
| 158 | m_pResults = new SqResults(this); |
| 159 | } |
| 160 | m_pResults->PushResult(); |
| 161 | } |
| 162 | |
| 163 | sqlite3 *db = m_pParent->GetDb(); |
| 164 | if (rc != SQLITE_OK && rc != SQLITE_DONE && rc == sqlite3_errcode(db)) |
| 165 | { |
| 166 | /* Something happened... */ |
| 167 | m_LastErrorCode = rc; |
| 168 | m_LastError.assign(sqlite3_errmsg(db)); |
| 169 | m_AffectedRows = 0; |
| 170 | m_InsertID = 0; |
| 171 | } else { |
| 172 | m_LastErrorCode = SQLITE_OK; |
| 173 | m_AffectedRows = (unsigned int)sqlite3_changes(db); |
| 174 | m_InsertID = (unsigned int)sqlite3_last_insert_rowid(db); |
| 175 | } |
| 176 | |
| 177 | /* Reset everything for the next execute */ |
| 178 | sqlite3_reset(m_pStmt); |
| 179 | sqlite3_clear_bindings(m_pStmt); |
| 180 | |
| 181 | return (m_LastErrorCode == SQLITE_OK); |
| 182 | } |
| 183 | |
| 184 | const char *SqQuery::GetError(int *errCode/* =NULL */) |
| 185 | { |
no test coverage detected