@Override public SQLiteConnection call() throws Exception { SQLiteConnection connection = useInMemoryDatabase.get() || IN_MEMORY_PATH.equals(path) ? new SQLiteConnection() : new SQLiteConnection(new File(path)); connection.open(); return connection; } });
@Override public Void call() throws Exception { connection.dispose(); return null; } }));
@Override public SQLiteStatement call() throws Exception { return connection.prepare(sql); } });
SQLiteConnection db = new SQLiteConnection(new File("/tmp/database")); db.open(true); ... SQLiteStatement st = db.prepare("SELECT order_id FROM orders WHERE quantity >= ?"); try { st.bind(1, minimumQuantity); while (st.step()) { orders.add(st.columnLong(0)); } } finally { st.dispose(); } ... db.dispose();
protected SQLiteConnection initialValue() { log.info(Thread.currentThread().getName() + " requests a new connection to " + dbFile); SQLiteConnection conn = new SQLiteConnection(dbFile); try { conn.open(true); conn.setExtensionLoadingEnabled(true); // TODO Make optional conn.exec("PRAGMA cache_size=20"); conn.exec(initStatement); if(conn != null && conn.isOpen()) { conn.dispose();
import com.almworks.sqlite4java.SQLiteConnection; import com.almworks.sqlite4java.SQLiteStatement; import org.junit.Test; import java.io.File; public class SqliteTest { @Test public void aTest() throws Exception { SQLiteConnection db = new SQLiteConnection(new File("/tmp/database")); db.open(true); SQLiteStatement st = db.prepare("SELECT name FROM dummy"); try { while(st.step()) { System.err.printf("name = %s\n", st.columnString(1)); } } finally { st.dispose(); } } }
public void initPartition(int partition, Path local) throws IOException, InterruptedException { try { LOG.info("Initializing SQL connection [" + partition + "]"); SQLiteConnection conn = new SQLiteConnection(new File(local.toString())); conn.open(true); conn.exec("PRAGMA temp_store_directory = '" + new File(".").getAbsolutePath() + "'"); SQLiteStatement st = conn.prepare("PRAGMA temp_store_directory"); st.step(); LOG.info("Changed temp_store_directory to: " + st.columnString(0)); conn.exec("PRAGMA journal_mode=OFF"); conn.exec("PRAGMA page_size=8192;"); connCache.put(partition, conn); conn.exec(sql); conn.exec("BEGIN"); Map<String, SQLiteStatement> stMap = new HashMap<String, SQLiteStatement>(); stCache.put(partition, stMap);
final SQLiteConnection db = new SQLiteConnection(new File("test.db")); try { db.open(); db.dispose(); System.out.println("Success"); } catch (Exception e) {
while(it.hasNext()) { SQLiteConnection conn = it.next(); log.info("-- Closed a connection pending diposal: " + conn.getDatabaseFile()); conn.dispose(); it.remove(); st = conn.prepare(query, false); if(timeoutThread != null) { timeoutThread.endQuery(conn);
checkThread(); SQLiteConnection destination = new SQLiteConnection(destinationDbFile).openV2(flags); if (Internal.isFineLogging()) { Internal.logFine(this, "initializeBackup to " + destination); SWIGTYPE_p_sqlite3 sourceDb = handle(); SWIGTYPE_p_sqlite3 destinationDb = destination.handle(); SWIGTYPE_p_sqlite3_backup backup = _SQLiteSwigged.sqlite3_backup_init(destinationDb, DEFAULT_DB_NAME, sourceDb, sourceDbName); if (backup == null) { try { int errorCode = destination.getErrorCode(); destination.throwResult(errorCode, "backup initialization"); throw new SQLiteException(SQLiteConstants.WRAPPER_WEIRD, "backup failed to start but error code is 0"); } finally { destination.dispose();
public SQLiteConnection createNewConnection() { try { SQLiteConnection conn; if (this.databaseFile != null) { conn = new SQLiteConnection(this.databaseFile); } else { conn = new SQLiteConnection(); } // open with "open or create" flag conn.open(true); conn.setBusyTimeout(30*1000); return conn; } catch (SQLiteException ex) { throw new IllegalStateException("Failed to open database.", ex); } }
public List<T> GetData<T> () where T: new() { using(var connection = new SQLiteConnection("..DB-path..")){ return connection.Table<T>.ToList(); } }
this.connection = new SQLiteConnection(dbLocation); this.connection.openReadonly(); this.connection.exec("PRAGMA synchronous=OFF;"); this.connection.exec("PRAGMA journal_mode=OFF;"); this.connection.exec("PRAGMA temp_store=2;"); this.connection.exec("PRAGMA cache_size=-100000;"); // around 100 Mo this.connection.exec("PRAGMA mmap_size=2147418112;"); // around 2 GB of mapped-memory (it may help for batch processing)
SQLiteConnection con = new SQLiteConnection(); con.exec("BEGIN"); // do transaction work - auto-commit is disabled con.exec("COMMIT"); // auto-commit is enabled again
@Override public void close() throws IOException, InterruptedException { try { for (Map.Entry<Integer, SQLiteConnection> entry : connCache.entrySet()) { LOG.info("Closing SQL connection [" + entry.getKey() + "]"); // entry.getValue().exec("COMMIT"); if (getPostSQL() != null) { LOG.info("Executing end SQL statements."); for (String sql : getPostSQL()) { LOG.info("Executing: " + sql); entry.getValue().exec(sql); } } entry.getValue().dispose(); } } catch (SQLiteException e) { throw new IOException(e); } catch (SploutSQLOutputFormatException e) { throw new IOException(e); } } }
public void close() { String thisThread = Thread.currentThread().getName(); for(ThreadAndConnection tConn: allOpenedConnections) { if(thisThread.equals(tConn.threadName)) { log.info("-- Closing my own connection to: " + tConn.conn.getDatabaseFile()); tConn.conn.dispose(); } else { // needs to be closed at some point by the owner Set<SQLiteConnection> set = CLEAN_UP_AFTER_YOURSELF.get(tConn.threadName); synchronized(set) { // just in case the owner of the set is iterating over it CLEAN_UP_AFTER_YOURSELF.get(tConn.threadName).add(tConn.conn); } } } // timeoutThread.interrupt(); } }
@Override public void close() { // it's not possible to call dispose from other threads // so the best we can do is call dispose on the connection // for the same thread as us SQLiteConnection conn = localConnection; if (conn != null && !conn.isDisposed()) { conn.dispose(); } }
/** * Opens the connection, creating database if needed. See {@link #open(boolean)} for a full description. * * @return this connection * @throws SQLiteException if SQLite returns an error, or if the call violates the contract of this class */ public SQLiteConnection open() throws SQLiteException { return open(true); }
SQLiteConnection mySQLite = new SQLiteConnection("Data Source=ytsongrequest.s3db;Version=3;"); mySQLite.Open(); x.ExecuteNonQuery(); mySQLite.Close();