congrats Icon
New! Announcing our next generation AI code completions
Read here
Tabnine Logo
SQLiteStatement.executeInsert
Code IndexAdd Tabnine to your IDE (free)

How to use
executeInsert
method
in
android.database.sqlite.SQLiteStatement

Best Java code snippets using android.database.sqlite.SQLiteStatement.executeInsert (Showing top 20 results out of 405)

origin: greenrobot/greenDAO

@Override
public long executeInsert() {
  return delegate.executeInsert();
}
origin: stackoverflow.com

 String sql = "INSERT INTO table_name (column_1, column_2) VALUES (57, 'hello')";
SQLiteStatement statement = db.compileStatement(sql);
long rowId = statement.executeInsert();
origin: stackoverflow.com

 String value = "one's self";
StringBuilder query= StringBuilder();
query.append("insert into tname(foo) values (?)");
SQLiteStatement stmt= db.compileStatement(query.toString());
stmt.bindString(1, value);
long rowId= stmt.executeInsert();
// do logic check for > -1 on success
origin: facebook/stetho

private <T> T executeInsert(
  SQLiteDatabase database,
  String query,
  ExecuteResultHandler<T> handler) {
 SQLiteStatement statement = database.compileStatement(query);
 long count = statement.executeInsert();
 return handler.handleInsert(count);
}
origin: stackoverflow.com

 String sql = "INSERT INTO table_name (column_1, column_2) VALUES (?, ?)";
SQLiteStatement statement = db.compileStatement(sql);

int intValue = 57;
String stringValue = "hello";

statement.bindLong(1, intValue); // These match to the two question marks in the sql string
statement.bindString(2, stringValue); 

long rowId = statement.executeInsert();
origin: greenrobot/greenDAO

private long insertInsideTx(T entity, DatabaseStatement stmt) {
  synchronized (stmt) {
    if (isStandardSQLite) {
      SQLiteStatement rawStmt = (SQLiteStatement) stmt.getRawStatement();
      bindValues(rawStmt, entity);
      return rawStmt.executeInsert();
    } else {
      bindValues(stmt, entity);
      return stmt.executeInsert();
    }
  }
}
origin: stackoverflow.com

 String stringValue = "hello";
try {

  db.beginTransaction();
  String sql = "INSERT INTO table_name (column_1, column_2) VALUES (?, ?)";
  SQLiteStatement statement = db.compileStatement(sql);

  for (int i = 0; i < 1000; i++) {
    statement.clearBindings();
    statement.bindLong(1, i);
    statement.bindString(2, stringValue + i);
    statement.executeInsert();
  }

  db.setTransactionSuccessful(); // This commits the transaction if there were no exceptions

} catch (Exception e) {
  Log.w("Exception:", e);
} finally {
  db.endTransaction();
}
origin: stackoverflow.com

 public void insertUser(){
  SQLiteDatabase db               =   dbHelper.getWritableDatabase();

  String delSql                       =   "DELETE FROM ACCOUNTS";
  SQLiteStatement delStmt         =   db.compileStatement(delSql);
  delStmt.execute();

  String sql                      =   "INSERT INTO ACCOUNTS (account_id,account_name,account_image) VALUES(?,?,?)";
  SQLiteStatement insertStmt      =   db.compileStatement(sql);
  insertStmt.clearBindings();
  insertStmt.bindString(1, Integer.toString(this.accId));
  insertStmt.bindString(2,this.accName);
  insertStmt.bindBlob(3, this.accImage);
  insertStmt.executeInsert();
  db.close();
}
origin: yigit/android-priority-jobqueue

private boolean insertWithTags(JobHolder jobHolder) {
  final SQLiteStatement stmt = sqlHelper.getInsertStatement();
  final SQLiteStatement tagsStmt = sqlHelper.getInsertTagsStatement();
  db.beginTransaction();
  try {
    stmt.clearBindings();
    bindValues(stmt, jobHolder);
    boolean insertResult = stmt.executeInsert() != -1;
    if (!insertResult) {
      return false;
    }
    for (String tag : jobHolder.getTags()) {
      tagsStmt.clearBindings();
      bindTag(tagsStmt, jobHolder.getId(), tag);
      tagsStmt.executeInsert();
    }
    db.setTransactionSuccessful();
    return true;
  } catch (Throwable t) {
    JqLog.e(t, "error while inserting job with tags");
    return false;
  }
  finally {
    db.endTransaction();
  }
}
origin: kaaproject/kaa

insertStatement.bindLong(1, currentBucketId);
insertStatement.bindBlob(2, record.getData());
long insertedId = insertStatement.executeInsert();
if (insertedId >= 0) {
 currentBucketSize += record.getSize();
origin: robolectric/robolectric

@Test
public void testExecuteInsertShouldCloseGeneratedKeysResultSet() throws Exception {
 // NOTE:
 // As a side-effect we will get "database locked" exception
 // on rollback if generatedKeys wasn't closed
 //
 // Don't know how suitable to use Mockito here, but
 // it will be a little bit simpler to test ShadowSQLiteStatement
 // if actualDBStatement will be mocked
 database.beginTransaction();
 try {
  SQLiteStatement insertStatement = database.compileStatement("INSERT INTO `routine` " +
    "(`name` ,`lastUsed`) VALUES ('test',0)");
  try {
   insertStatement.executeInsert();
  } finally {
   insertStatement.close();
  }
 } finally {
  database.endTransaction();
 }
}
origin: stackoverflow.com

 private void insertTestData() {
  String sql = "insert into producttable (name, description, price, stock_available) values (?, ?, ?, ?);";

  dbHandler.getWritableDatabase();
  database.beginTransaction();
  SQLiteStatement stmt = database.compileStatement(sql);

  for (int i = 0; i < NUMBER_OF_ROWS; i++) {
    //generate some values

    stmt.bindString(1, randomName);
    stmt.bindString(2, randomDescription);
    stmt.bindDouble(3, randomPrice);
    stmt.bindLong(4, randomNumber);

    long entryID = stmt.executeInsert();
    stmt.clearBindings();
  }

  database.setTransactionSuccessful();
  database.endTransaction();

  dbHandler.close();
}
origin: yigit/android-priority-jobqueue

/**
 * {@inheritDoc}
 */
@Override
public boolean insert(@NonNull JobHolder jobHolder) {
  persistJobToDisk(jobHolder);
  if (jobHolder.hasTags()) {
    return insertWithTags(jobHolder);
  }
  final SQLiteStatement stmt = sqlHelper.getInsertStatement();
  stmt.clearBindings();
  bindValues(stmt, jobHolder);
  long insertId = stmt.executeInsert();
  // insert id is a alias to row_id
  jobHolder.setInsertionOrder(insertId);
  return insertId != -1;
}
origin: robolectric/robolectric

@Test
public void testExecuteInsert() throws Exception {
 SQLiteStatement insertStatement = database.compileStatement("INSERT INTO `routine` (`name` ,`lastUsed` ) VALUES (?,?)");
 insertStatement.bindString(1, "Leg Press");
 insertStatement.bindLong(2, 0);
 long pkeyOne = insertStatement.executeInsert();
 insertStatement.clearBindings();
 insertStatement.bindString(1, "Bench Press");
 insertStatement.bindLong(2, 1);
 long pkeyTwo = insertStatement.executeInsert();
 assertThat(pkeyOne).isEqualTo(1L);
 assertThat(pkeyTwo).isEqualTo(2L);
 Cursor dataCursor = database.rawQuery("SELECT COUNT(*) FROM `routine`", null);
 assertThat(dataCursor.moveToFirst()).isTrue();
 assertThat(dataCursor.getInt(0)).isEqualTo(2);
 dataCursor.close();
 dataCursor = database.rawQuery("SELECT `id`, `name` ,`lastUsed` FROM `routine`", null);
 assertThat(dataCursor.moveToNext()).isTrue();
 assertThat(dataCursor.getInt(0)).isEqualTo(1);
 assertThat(dataCursor.getString(1)).isEqualTo("Leg Press");
 assertThat(dataCursor.getInt(2)).isEqualTo(0);
 assertThat(dataCursor.moveToNext()).isTrue();
 assertThat(dataCursor.getLong(0)).isEqualTo(2L);
 assertThat(dataCursor.getString(1)).isEqualTo("Bench Press");
 assertThat(dataCursor.getInt(2)).isEqualTo(1);
 dataCursor.close();
}
origin: robolectric/robolectric

@Test
public void testExecuteUpdateDelete() throws Exception {
 SQLiteStatement insertStatement = database.compileStatement("INSERT INTO `routine` (`name`) VALUES (?)");
 insertStatement.bindString(1, "Hand Press");
 long pkeyOne = insertStatement.executeInsert();
 assertThat(pkeyOne).isEqualTo(1);
 SQLiteStatement updateStatement = database.compileStatement("UPDATE `routine` SET `name`=? WHERE `id`=?");
 updateStatement.bindString(1, "Head Press");
 updateStatement.bindLong(2, pkeyOne);
 assertThat(updateStatement.executeUpdateDelete()).isEqualTo(1);
 Cursor dataCursor = database.rawQuery("SELECT `name` FROM `routine`", null);
 assertThat(dataCursor.moveToNext()).isTrue();
 assertThat(dataCursor.getString(0)).isEqualTo("Head Press");
}
origin: yigit/android-priority-jobqueue

/**
 * {@inheritDoc}
 */
@Override
public boolean insertOrReplace(@NonNull JobHolder jobHolder) {
  if (jobHolder.getInsertionOrder() == null) {
    return insert(jobHolder);
  }
  persistJobToDisk(jobHolder);
  jobHolder.setRunningSessionId(JobManager.NOT_RUNNING_SESSION_ID);
  SQLiteStatement stmt = sqlHelper.getInsertOrReplaceStatement();
  stmt.clearBindings();
  bindValues(stmt, jobHolder);
  boolean result = stmt.executeInsert() != -1;
  JqLog.d("reinsert job result %s", result);
  return result;
}
origin: robolectric/robolectric

 @Test
 public void testCloseShouldCloseUnderlyingPreparedStatement() throws Exception {
  SQLiteStatement insertStatement = database.compileStatement("INSERT INTO `routine` (`name`) VALUES (?)");
  insertStatement.bindString(1, "Hand Press");
  insertStatement.close();
  try {
   insertStatement.executeInsert();
   fail();
  } catch (Exception e) {
   assertThat(e).isInstanceOf(IllegalStateException.class);
  }
 }
}
origin: robolectric/robolectric

@Test
public void simpleQueryTest() throws Exception {
 SQLiteStatement stmt = database.compileStatement("SELECT count(*) FROM `countme`");
 assertThat(stmt.simpleQueryForLong()).isEqualTo(0L);
 assertThat(stmt.simpleQueryForString()).isEqualTo("0");
 SQLiteStatement insertStatement = database.compileStatement("INSERT INTO `countme` (`name` ,`lastUsed` ) VALUES (?,?)");
 insertStatement.bindString(1, "Leg Press");
 insertStatement.bindLong(2, 0);
 insertStatement.executeInsert();
 assertThat(stmt.simpleQueryForLong()).isEqualTo(1L);
 assertThat(stmt.simpleQueryForString()).isEqualTo("1");
 insertStatement.bindString(1, "Bench Press");
 insertStatement.bindLong(2, 1);
 insertStatement.executeInsert();
 assertThat(stmt.simpleQueryForLong()).isEqualTo(2L);
 assertThat(stmt.simpleQueryForString()).isEqualTo("2");
}
origin: greenrobot/greenDAO

bindValues(rawStmt, entity);
if (setPrimaryKey) {
  long rowId = rawStmt.executeInsert();
  updateKeyAfterInsertAndAttach(entity, rowId, false);
} else {
origin: andpor/react-native-sqlite-storage

insertId = myStatement.executeInsert();
android.database.sqliteSQLiteStatementexecuteInsert

Popular methods of SQLiteStatement

  • bindLong
  • bindString
  • clearBindings
  • close
  • execute
  • bindDouble
  • bindBlob
  • executeUpdateDelete
  • simpleQueryForLong
  • bindNull
  • simpleQueryForString
  • bindAllArgsAsStrings
  • simpleQueryForString,
  • bindAllArgsAsStrings,
  • bindDate,
  • bindInt,
  • bindInteger,
  • bindValue,
  • simpleQueryForBlobFileDescriptor,
  • toString

Popular in Java

  • Reactive rest calls using spring rest template
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • getApplicationContext (Context)
  • compareTo (BigDecimal)
  • FileWriter (java.io)
    A specialized Writer that writes to a file in the file system. All write requests made by calling me
  • Collection (java.util)
    Collection is the root of the collection hierarchy. It defines operations on data collections and t
  • TimeZone (java.util)
    TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a
  • Notification (javax.management)
  • Reference (javax.naming)
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • Top 15 Vim Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now