@@ -51,9 +51,11 @@ int rcpp_import_to_trip_table (const char* bikedb,
51
51
{
52
52
sqlite3 *dbcon;
53
53
char *zErrMsg = nullptr ;
54
+ const char *zVfs = nullptr ;
54
55
size_t rc;
55
56
56
- rc = static_cast <size_t > (sqlite3_open_v2 (bikedb, &dbcon, SQLITE_OPEN_READWRITE, nullptr ));
57
+ rc = static_cast <size_t > (sqlite3_open_v2 (bikedb, &dbcon, SQLITE_OPEN_READWRITE, zVfs));
58
+ // rc = static_cast <size_t> (sqlite3_open(bikedb, &dbcon));
57
59
if (rc != SQLITE_OK)
58
60
throw std::runtime_error (" Can't establish sqlite3 connection" );
59
61
@@ -90,6 +92,7 @@ int rcpp_import_to_trip_table (const char* bikedb,
90
92
sqlite3_prepare_v2 (dbcon, sqlqry, BUFFER_SIZE, &stmt, nullptr );
91
93
92
94
sqlite3_exec (dbcon, " BEGIN TRANSACTION" , nullptr , nullptr , &zErrMsg);
95
+ sqlite3_free (zErrMsg);
93
96
94
97
for (int filenum = 0 ; filenum < datafiles.length (); filenum++)
95
98
{
@@ -172,8 +175,10 @@ int rcpp_import_to_trip_table (const char* bikedb,
172
175
}
173
176
}
174
177
}
178
+ sqlite3_finalize (stmt);
175
179
176
180
sqlite3_exec (dbcon, " END TRANSACTION" , nullptr , nullptr , &zErrMsg);
181
+ sqlite3_free (zErrMsg);
177
182
178
183
if (city == " ny" || city == " bo" || city == " la" || city == " ph" )
179
184
import_to_station_table (dbcon, stationqry);
@@ -218,14 +223,19 @@ int rcpp_import_to_file_table (const char * bikedb,
218
223
datafile_qry += std::to_string (nfiles) + " ,\" " + city + " \" ,\" " +
219
224
i + " \" );" ;
220
225
221
- rc = sqlite3_exec (dbcon, datafile_qry.c_str (), nullptr , nullptr , &zErrMsg);
226
+ const char *sql = datafile_qry.c_str ();
227
+ rc = sqlite3_exec (dbcon, sql, nullptr , nullptr , &zErrMsg);
228
+ sqlite3_free (zErrMsg);
229
+ // rc = sqlite3_exec(dbcon, datafile_qry.c_str(), nullptr, nullptr, &zErrMsg);
222
230
if (rc == 0 )
223
231
nfiles++;
224
232
}
225
233
226
234
rc = sqlite3_close_v2 (dbcon);
235
+ // rc = sqlite3_close(dbcon);
227
236
if (rc != SQLITE_OK)
228
237
throw std::runtime_error (" Unable to close sqlite database" );
238
+ sqlite3_free (zErrMsg);
229
239
230
240
return nfiles;
231
241
}
0 commit comments