Java Code Examples for android.database.sqlite.SQLiteStatement.bindNull()

The following are Jave code examples for showing how to use bindNull() of the android.database.sqlite.SQLiteStatement class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: OftenPorter   File: SqliteHandle.java   Source Code and License Vote up 6 votes
private void bind(int index, Object value, SQLiteStatement sQLiteStatement)
{
    if (value == null)
    {
        sQLiteStatement.bindNull(index);
    } else
    {
        int i = Arrays.binarySearch(TYPES_ADD, TypeUtil.Type.forSearch(value.getClass()));
        if (i >= 0)
        {
            TypeUtil.Type<TypeUtil.StatementObj> type = TYPES_MULTI_ADD[i];
            type.put(null, value, new TypeUtil.StatementObj(index, sQLiteStatement));
        } else
        {
            throw new DBException("unknown type of " + value.getClass() + " for sqlite");
        }

    }
}
 
Example 2
Project: GitHub   File: SqlInfo.java   Source Code and License Vote up 5 votes
public SQLiteStatement buildStatement(SQLiteDatabase database) {
    SQLiteStatement result = database.compileStatement(sql);
    if (bindArgs != null) {
        for (int i = 1; i < bindArgs.size() + 1; i++) {
            KeyValue kv = bindArgs.get(i - 1);
            Object value = ColumnUtils.convert2DbValueIfNeeded(kv.value);
            if (value == null) {
                result.bindNull(i);
            } else {
                ColumnConverter converter = ColumnConverterFactory.getColumnConverter(value.getClass());
                ColumnDbType type = converter.getColumnDbType();
                switch (type) {
                    case INTEGER:
                        result.bindLong(i, ((Number) value).longValue());
                        break;
                    case REAL:
                        result.bindDouble(i, ((Number) value).doubleValue());
                        break;
                    case TEXT:
                        result.bindString(i, value.toString());
                        break;
                    case BLOB:
                        result.bindBlob(i, (byte[]) value);
                        break;
                    default:
                        result.bindNull(i);
                        break;
                } // end switch
            }
        }
    }
    return result;
}
 
Example 3
Project: PeSanKita-android   File: PlaintextBackupImporter.java   Source Code and License Vote up 5 votes
private static void addEncryptedStingToStatement(MasterCipher masterCipher, SQLiteStatement statement, int index, String value) {
  if (value == null || value.equals("null")) {
    statement.bindNull(index);
  } else {
    statement.bindString(index, masterCipher.encryptBody(value));
  }
}
 
Example 4
Project: PeSanKita-android   File: SmsMigrator.java   Source Code and License Vote up 5 votes
private static void addEncryptedStringToStatement(Context context, SQLiteStatement statement,
                                                  Cursor cursor, MasterSecret masterSecret,
                                                  int index, String key)
{
  int columnIndex = cursor.getColumnIndexOrThrow(key);

  if (cursor.isNull(columnIndex)) {
    statement.bindNull(index);
  } else {
    statement.bindString(index, encrypt(masterSecret, cursor.getString(columnIndex)));
  }
}
 
Example 5
Project: PeSanKita-android   File: SmsMigrator.java   Source Code and License Vote up 5 votes
private static void addStringToStatement(SQLiteStatement statement, Cursor cursor,
                                         int index, String key)
{
  int columnIndex = cursor.getColumnIndexOrThrow(key);

  if (cursor.isNull(columnIndex)) {
    statement.bindNull(index);
  } else {
    statement.bindString(index, cursor.getString(columnIndex));
  }
}
 
Example 6
Project: PeSanKita-android   File: SmsMigrator.java   Source Code and License Vote up 5 votes
private static void addIntToStatement(SQLiteStatement statement, Cursor cursor,
                                      int index, String key)
{
  int columnIndex = cursor.getColumnIndexOrThrow(key);

  if (cursor.isNull(columnIndex)) {
    statement.bindNull(index);
  } else {
    statement.bindLong(index, cursor.getLong(columnIndex));
  }
}
 
Example 7
Project: Geoclick   File: DBHelper.java   Source Code and License Vote up 5 votes
public void Picture_Insert(String country, String city, String latitude, String longitude,
                           byte[] thumbnail, String mainImg) {

    // open read and write database
    SQLiteDatabase db = getWritableDatabase();
    // execute insert query

    SQLiteStatement p = db.compileStatement("INSERT INTO Picture values(?,?,?,?,?,?,?);");
    p.bindNull(1);
    p.bindString(2, country);
    p.bindString(3, city);
    p.bindString(4, latitude);
    p.bindString(5, longitude);
    p.bindBlob(6, thumbnail);
    p.bindString(7, mainImg);
    p.execute();
    db.close();
    Log.d("Database :", "INSERT Complete!");
}
 
Example 8
Project: Cable-Android   File: PlaintextBackupImporter.java   Source Code and License Vote up 5 votes
private static void addEncryptedStringToStatement(MasterCipher masterCipher, SQLiteStatement statement, int index, String value) {
  if (value == null || value.equals("null")) {
    statement.bindNull(index);
  } else {
    statement.bindString(index, masterCipher.encryptBody(value));
  }
}
 
Example 9
Project: Cable-Android   File: SmsMigrator.java   Source Code and License Vote up 5 votes
private static void addEncryptedStringToStatement(Context context, SQLiteStatement statement,
                                                  Cursor cursor, MasterSecret masterSecret,
                                                  int index, String key)
{
  int columnIndex = cursor.getColumnIndexOrThrow(key);

  if (cursor.isNull(columnIndex)) {
    statement.bindNull(index);
  } else {
    statement.bindString(index, encrypt(masterSecret, cursor.getString(columnIndex)));
  }
}
 
Example 10
Project: Cable-Android   File: SmsMigrator.java   Source Code and License Vote up 5 votes
private static void addStringToStatement(SQLiteStatement statement, Cursor cursor,
                                         int index, String key)
{
  int columnIndex = cursor.getColumnIndexOrThrow(key);

  if (cursor.isNull(columnIndex)) {
    statement.bindNull(index);
  } else {
    statement.bindString(index, cursor.getString(columnIndex));
  }
}
 
Example 11
Project: Cable-Android   File: SmsMigrator.java   Source Code and License Vote up 5 votes
private static void addIntToStatement(SQLiteStatement statement, Cursor cursor,
                                      int index, String key)
{
  int columnIndex = cursor.getColumnIndexOrThrow(key);

  if (cursor.isNull(columnIndex)) {
    statement.bindNull(index);
  } else {
    statement.bindLong(index, cursor.getLong(columnIndex));
  }
}
 
Example 12
Project: wallpaperboard   File: Database.java   Source Code and License Vote up 5 votes
public void updateWallpapers(@NonNull List<Wallpaper> wallpapers) {
    if (!openDatabase()) {
        LogUtil.e("Database error: updateWallpapers() failed to open database");
        return;
    }

    String query = "UPDATE " +TABLE_WALLPAPERS+ " SET " +KEY_FAVORITE+ " = ?, " +KEY_SIZE+ " = ?, "
            +KEY_MIME_TYPE+ " = ?, " +KEY_WIDTH+ " = ?," +KEY_HEIGHT+ " = ?, " +KEY_COLOR+ " = ? "
            +"WHERE " +KEY_URL+ " = ?";
    SQLiteStatement statement = mDatabase.get().mSQLiteDatabase.compileStatement(query);
    mDatabase.get().mSQLiteDatabase.beginTransaction();

    for (Wallpaper wallpaper : wallpapers) {
        statement.clearBindings();

        statement.bindLong(1, wallpaper.isFavorite() ? 1 : 0);
        statement.bindLong(2, wallpaper.getSize());

        String mimeType = wallpaper.getMimeType();
        if (mimeType != null) {
            statement.bindString(3, mimeType);
        } else {
            statement.bindNull(3);
        }

        ImageSize dimension = wallpaper.getDimensions();
        int width = dimension == null ? 0 : dimension.getWidth();
        int height = dimension == null ? 0 : dimension.getHeight();
        statement.bindLong(4, width);
        statement.bindLong(5, height);

        statement.bindLong(6, wallpaper.getColor());
        statement.bindString(7, wallpaper.getUrl());
        statement.execute();
    }

    mDatabase.get().mSQLiteDatabase.setTransactionSuccessful();
    mDatabase.get().mSQLiteDatabase.endTransaction();
}
 
Example 13
Project: PeSanKita-android   File: PlaintextBackupImporter.java   Source Code and License Vote up 4 votes
private static void addStringToStatement(SQLiteStatement statement, int index, String value) {
  if (value == null || value.equals("null")) statement.bindNull(index);
  else                                       statement.bindString(index, value);
}
 
Example 14
Project: PeSanKita-android   File: PlaintextBackupImporter.java   Source Code and License Vote up 4 votes
private static void addNullToStatement(SQLiteStatement statement, int index) {
  statement.bindNull(index);
}
 
Example 15
Project: Cable-Android   File: PlaintextBackupImporter.java   Source Code and License Vote up 4 votes
private static void addStringToStatement(SQLiteStatement statement, int index, String value) {
  if (value == null || value.equals("null")) statement.bindNull(index);
  else                                       statement.bindString(index, value);
}
 
Example 16
Project: Cable-Android   File: PlaintextBackupImporter.java   Source Code and License Vote up 4 votes
private static void addNullToStatement(SQLiteStatement statement, int index) {
  statement.bindNull(index);
}
 
Example 17
Project: wallpaperboard   File: Database.java   Source Code and License Vote up 4 votes
public void add(@NonNull List<?> categoryLIst, @NonNull List<?> wallpaperList) {
    if (!openDatabase()) {
        LogUtil.e("Database error: add() failed to open database");
        return;
    }

    Iterator categoryIterator = categoryLIst.iterator();
    Iterator wallpaperIterator = wallpaperList.iterator();
    int size = categoryLIst.size() > wallpaperList.size() ? categoryLIst.size() : wallpaperList.size();

    String categoryQuery = "INSERT OR IGNORE INTO " +TABLE_CATEGORIES+ " (" +KEY_NAME+ ") VALUES (?);";
    String wallpaperQuery = "INSERT OR IGNORE INTO " +TABLE_WALLPAPERS+ " (" +KEY_NAME+ "," +KEY_AUTHOR+ "," +KEY_URL+ ","
            +KEY_THUMB_URL+ "," +KEY_CATEGORY+ "," +KEY_ADDED_ON+ ") VALUES (?,?,?,?,?,?);";

    SQLiteStatement categoryStatements = mDatabase.get().mSQLiteDatabase.compileStatement(categoryQuery);
    SQLiteStatement wallpaperStatements = mDatabase.get().mSQLiteDatabase.compileStatement(wallpaperQuery);
    mDatabase.get().mSQLiteDatabase.beginTransaction();

    int i = 0;
    do {
        categoryStatements.clearBindings();
        wallpaperStatements.clearBindings();

        if (categoryIterator.hasNext()) {
            Category category;
            if (categoryIterator.next() instanceof Category) {
                category = (Category) categoryLIst.get(i);
            } else {
                category = JsonHelper.getCategory(categoryLIst.get(i));
            }

            if (category != null) {
                categoryStatements.bindString(1, category.getName());
                categoryStatements.execute();
            }
        }

        if (wallpaperIterator.hasNext()) {
            Wallpaper wallpaper;
            if (wallpaperIterator.next() instanceof Wallpaper) {
                wallpaper = (Wallpaper) wallpaperList.get(i);
            } else {
                wallpaper = JsonHelper.getWallpaper(wallpaperList.get(i));
            }

            if (wallpaper != null) {
                if (wallpaper.getUrl() != null) {
                    String name = wallpaper.getName();
                    if (name == null) name = "";

                    wallpaperStatements.bindString(1, name);

                    if (wallpaper.getAuthor() != null) {
                        wallpaperStatements.bindString(2, wallpaper.getAuthor());
                    } else {
                        wallpaperStatements.bindNull(2);
                    }

                    wallpaperStatements.bindString(3, wallpaper.getUrl());
                    wallpaperStatements.bindString(4, wallpaper.getThumbUrl());
                    wallpaperStatements.bindString(5, wallpaper.getCategory());
                    wallpaperStatements.bindString(6, TimeHelper.getLongDateTime());
                    wallpaperStatements.execute();
                }
            }
        }
        i++;
    } while (i < size);

    mDatabase.get().mSQLiteDatabase.setTransactionSuccessful();
    mDatabase.get().mSQLiteDatabase.endTransaction();
}
 
Example 18
Project: wallpaperboard   File: Database.java   Source Code and License Vote up 4 votes
public void addWallpapers(@NonNull List<?> list) {
    if (!openDatabase()) {
        LogUtil.e("Database error: addWallpapers() failed to open database");
        return;
    }

    String query = "INSERT OR IGNORE INTO " +TABLE_WALLPAPERS+ " (" +KEY_NAME+ "," +KEY_AUTHOR+ "," +KEY_URL+ ","
            +KEY_THUMB_URL+ "," +KEY_CATEGORY+ "," +KEY_ADDED_ON+ ") VALUES (?,?,?,?,?,?);";
    SQLiteStatement statement = mDatabase.get().mSQLiteDatabase.compileStatement(query);
    mDatabase.get().mSQLiteDatabase.beginTransaction();

    for (int i = 0; i < list.size(); i++) {
        statement.clearBindings();

        Wallpaper wallpaper;
        if (list.get(i) instanceof Wallpaper) {
            wallpaper = (Wallpaper) list.get(i);
        } else {
            wallpaper = JsonHelper.getWallpaper(list.get(i));
        }

        if (wallpaper != null) {
            if (wallpaper.getUrl() != null) {
                String name = wallpaper.getName();
                if (name == null) name = "";

                statement.bindString(1, name);

                if (wallpaper.getAuthor() != null) {
                    statement.bindString(2, wallpaper.getAuthor());
                } else {
                    statement.bindNull(2);
                }

                statement.bindString(3, wallpaper.getUrl());
                statement.bindString(4, wallpaper.getThumbUrl());
                statement.bindString(5, wallpaper.getCategory());
                statement.bindString(6, TimeHelper.getLongDateTime());
                statement.execute();
            }
        }
    }
    mDatabase.get().mSQLiteDatabase.setTransactionSuccessful();
    mDatabase.get().mSQLiteDatabase.endTransaction();
}