From ae5a0007d06b5a03a74bd228c1bd30f513a67817 Mon Sep 17 00:00:00 2001 From: Justin Clift Date: Sat, 22 Apr 2023 14:57:08 +1000 Subject: [PATCH] common: No need to prepare the SQLite statement before execution --- common/sqlite.go | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/common/sqlite.go b/common/sqlite.go index f23a4c086..3ff309c1f 100644 --- a/common/sqlite.go +++ b/common/sqlite.go @@ -786,7 +786,7 @@ func ReadSQLiteDBCols(sdb *sqlite.Conn, dbTable, sortCol, sortDir string, ignore // ReadSQLiteDBCSV is a specialised variation of the ReadSQLiteDB() function, just for our CSV exporting code. It may // be merged with that in future. func ReadSQLiteDBCSV(sdb *sqlite.Conn, dbTable string) ([][]string, error) { - // Retrieve all of the data from the selected database table + // Retrieve all the data from the selected database table stmt, err := sdb.Prepare(`SELECT * FROM "` + dbTable + `"`) if err != nil { log.Printf("Error when preparing statement for database: %s\n", err) @@ -965,18 +965,8 @@ func SQLiteExecuteQueryLive(baseDir, dbOwner, dbName, loggedInUser, query string // TODO: Probably add in the before and after logging info at some point (as per query function), // so we can analyse query execution times, memory use, etc - // Prepare the statement - // FIXME: Do we need to do this prepare step? Am suspecting "no", as we don't (yet) have a way to - // batch call the matching stmt.Exec() below. Not remembering what else it might benefit though. - var stmt *sqlite.Stmt - stmt, err = sdb.Prepare(query) - if err != nil { - return - } - defer stmt.Finalize() - // Execute the statement - rowsChanged, err = stmt.ExecDml() + rowsChanged, err = sdb.ExecDml(query) if err != nil { log.Printf("Error when executing query by '%s' for LIVE database (%s/%s): '%s'\n", SanitiseLogString(loggedInUser), SanitiseLogString(dbOwner), SanitiseLogString(dbName),