func PrepareSQLiteDB(tx *sql.Tx, querySet SQLQuerySet, table string, createIndexes bool) error {
	// Recreate SQLite database tables.
	//
	// TODO: Research syncing tables instead of recreating each time

	// FIXME: What is a better way to drop the table programatically?
	dropTableStmt := fmt.Sprintf("DROP TABLE IF EXISTS %s", table)
	if _, err := tx.Exec(dropTableStmt); err != nil {
		log.Errorf(
			"failed to run query to drop (potentially) preexisting table %s: %v",
			table,
			err,
		)
		return err
	}
	log.Debugf("Successfully ran DROP TABLE query for table %s", table)

	dropIndexStmt := fmt.Sprintf("DROP INDEX IF EXISTS %s", table)
	if _, err := tx.Exec(dropIndexStmt); err != nil {
		log.Errorf(
			"failed to run query to drop (potentially) preexisting index for table %s: %v",
			table,
			err,
		)
		return err
	}
	log.Debugf("Successfully ran DROP INDEX query for table %s", table)

	if _, err := tx.Exec(querySet[SQLQueriesNew]); err != nil {
		log.Errorf(
			"failed to run query to create table %s: %v",
			table,
			err,
		)
		return err
	}
	log.Debugf("Created table %s in SQLite database", table)

	// Q: does this cause an error?
	// A: no, attempting to retrieve a key *not* in a map returns a zero
	// value, in this case an empty string value. Executing an empty
	// string/query appears to be "valid", which gives unexpected results.
	// Our validation method will have to catch problems like this one.
	//
	// if _, err := sqliteDB.Exec(""); err != nil {
	// 	log.Errorf(
	// 		"failed to run empty exec query for table %s",
	// 		table,
	// 		err,
	// 	)
	//	return
	// }

	if createIndexes {
		if _, err := tx.Exec(querySet[SQLQueriesIndex]); err != nil {

			log.Errorf(
				"failed to run query to create index for table %s: %v",
				table,
				err,
			)
			return err
		}
		log.Debugf("Created index for table %s in SQLite database", table)
	}

	log.Debug("SQLite database is ready")
	return nil
}
// PrepareSQLiteDB prepares a SQLite database for incoming data from the
// source database. As of the current version, this includes dropping tables
// and recreating them along with optional indexes, if enabled.
PrepareSQLiteDB prepares a SQLite database for incoming data from the
source database. As of the current version, this includes dropping tables
and recreating them along with optional indexes, if enabled.
// PrepareSQLiteDB prepares a SQLite database for incoming data from the // source database . As of the current version this includes dropping tables // and recreating them along with optional indexes if enabled .
func PrepareSQLiteDB(tx *sql.Tx, querySet SQLQuerySet, table string, createIndexes bool) error {
	 TODO: Research syncing tables instead of recreating each time
	 FIXME: What is a better way to drop the table programatically?
	dropTableStmt := fmt.Sprintf("DROP TABLE IF EXISTS %s", table)
	if _, err := tx.Exec(dropTableStmt); err != nil {
		log.Errorf(
			"failed to run query to drop (potentially) preexisting table %s: %v",
			table,
			err,
		)
		return err
	}
	log.Debugf("Successfully ran DROP TABLE query for table %s", table)
	dropIndexStmt := fmt.Sprintf("DROP INDEX IF EXISTS %s", table)
	if _, err := tx.Exec(dropIndexStmt); err != nil {
		log.Errorf(
			"failed to run query to drop (potentially) preexisting index for table %s: %v",
			table,
			err,
		)
		return err
	}
	log.Debugf("Successfully ran DROP INDEX query for table %s", table)
	if _, err := tx.Exec(querySet[SQLQueriesNew]); err != nil {
		log.Errorf(
			"failed to run query to create table %s: %v",
			table,
			err,
		)
		return err
	}
	log.Debugf("Created table %s in SQLite database", table)
	 Q: does this cause an error?
	 A: no, attempting to retrieve a key *not* in a map returns a zero
	 value, in this case an empty string value. Executing an empty
	 string/query appears to be "valid", which gives unexpected results.
	 Our validation method will have to catch problems like this one.
	 if _, err := sqliteDB.Exec(""); err != nil {
	 	log.Errorf(
	 		"failed to run empty exec query for table %s",
	 		table,
	 		err,
	 	)
		return
	 }
	if createIndexes {
		if _, err := tx.Exec(querySet[SQLQueriesIndex]); err != nil {
			log.Errorf(
				"failed to run query to create index for table %s: %v",
				table,
				err,
			)
			return err
		}
		log.Debugf("Created index for table %s in SQLite database", table)
	}
	log.Debug("SQLite database is ready")
	return nil
}
func PrepareSQLiteDB ( tx * sql . Tx , querySet SQLQuerySet , table string , createIndexes bool ) error { dropTableStmt := fmt . Sprintf ( " " , table ) if _ , err := tx . Exec ( dropTableStmt ) ; err != nil { log . Errorf ( " " , table , err , ) return err } log . Debugf ( " " , table ) dropIndexStmt := fmt . Sprintf ( " " , table ) if _ , err := tx . Exec ( dropIndexStmt ) ; err != nil { log . Errorf ( " " , table , err , ) return err } log . Debugf ( " " , table ) if _ , err := tx . Exec ( querySet [ SQLQueriesNew ] ) ; err != nil { log . Errorf ( " " , table , err , ) return err } log . Debugf ( " " , table ) if createIndexes { if _ , err := tx . Exec ( querySet [ SQLQueriesIndex ] ) ; err != nil { log . Errorf ( " " , table , err , ) return err } log . Debugf ( " " , table ) } log . Debug ( " " ) return nil }
PrepareSQLiteDB prepares a SQLite database for incoming data from the
source database.
PrepareSQLiteDB prepares a SQLite database for incoming data from the source database .
// Recreate SQLite database tables. // // TODO: Research syncing tables instead of recreating each time // FIXME: What is a better way to drop the table programatically? // Q: does this cause an error? // A: no, attempting to retrieve a key *not* in a map returns a zero // value, in this case an empty string value. Executing an empty // string/query appears to be "valid", which gives unexpected results. // Our validation method will have to catch problems like this one. // // if _, err := sqliteDB.Exec(""); err != nil { // 	log.Errorf( // 		"failed to run empty exec query for table %s", // 		table, // 		err, // 	) //	return // }