| 137 | } |
| 138 | |
| 139 | bool Annotations::Add(int side, double x, double y, const std::string &net, const std::string &part, const std::string &pin, const std::string ¬e) { |
| 140 | static const char sql[] = "INSERT INTO annotations (visible, side, posx, posy, net, part, pin, note) VALUES (1, ?, ?, ?, ?, ?, ?, ?);"; |
| 141 | |
| 142 | if (!sqldb && !Open(true)) { |
| 143 | SDL_LogError(SDL_LOG_CATEGORY_ERROR, "%s", "Annotations could not be added, database failed to open"); |
| 144 | return false; |
| 145 | } |
| 146 | |
| 147 | sqlite3_stmt *stmt; |
| 148 | int r = sqlite3_prepare_v2(sqldb, sql, -1, &stmt, NULL); |
| 149 | if (r != SQLITE_OK) { |
| 150 | SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Annotations INSERT statement could not be prepared: %s", sqlite3_errmsg(sqldb)); |
| 151 | return false; |
| 152 | } |
| 153 | |
| 154 | r = sqlite3_bind_int(stmt, 1, side); |
| 155 | |
| 156 | if (r == SQLITE_OK) { |
| 157 | r = sqlite3_bind_double(stmt, 2, x); |
| 158 | } |
| 159 | |
| 160 | if (r == SQLITE_OK) { |
| 161 | r = sqlite3_bind_double(stmt, 3, y); |
| 162 | } |
| 163 | |
| 164 | if (r == SQLITE_OK) { |
| 165 | r = sqlite3_bind_text(stmt, 4, net.c_str(), -1, SQLITE_TRANSIENT); |
| 166 | } |
| 167 | |
| 168 | if (r == SQLITE_OK) { |
| 169 | r = sqlite3_bind_text(stmt, 5, part.c_str(), -1, SQLITE_TRANSIENT); |
| 170 | } |
| 171 | |
| 172 | if (r == SQLITE_OK) { |
| 173 | r = sqlite3_bind_text(stmt, 6, pin.c_str(), -1, SQLITE_TRANSIENT); |
| 174 | } |
| 175 | |
| 176 | if (r == SQLITE_OK) { |
| 177 | r = sqlite3_bind_text(stmt, 7, note.c_str(), -1, SQLITE_TRANSIENT); |
| 178 | } |
| 179 | |
| 180 | if (r != SQLITE_OK) { |
| 181 | SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Annotations INSERT statement parameter could not be bound: %s", sqlite3_errmsg(sqldb)); |
| 182 | r = sqlite3_finalize(stmt); |
| 183 | return false; |
| 184 | } |
| 185 | |
| 186 | r = sqlite3_step(stmt); |
| 187 | |
| 188 | sqlite3_finalize(stmt); |
| 189 | |
| 190 | if (r != SQLITE_DONE && r != SQLITE_OK) { |
| 191 | SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Annotations INSERT statement failed: %s", sqlite3_errmsg(sqldb)); |
| 192 | } |
| 193 | |
| 194 | return true; |
| 195 | } |
| 196 | |