Back to project page SQLiteDatabase.
The source code is released under:
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004 Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> Everyone is permitted to copy and distribute v...
If you think the Android project SQLiteDatabase listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/* * Intellectual properties of Supun Lakshan Wanigarathna Dissanayake * Copyright (c) 2014, Supun Lakshan Wanigarathna Dissanayake. All rights reserved. * Created on : Jun 11, 2014, 8:19:33 PM *//*from ww w .jav a2s . c o m*/ package org.xfinity.android_sqlite_database_example.db; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteStatement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** * @author Supun Lakshan Wanigarathna Dissanayake * @mobile +94711290392 * @email supunlakshan.xfinity@gmail.com */ public class DbHandler { public static void performExecute(@NotNull SQLiteDatabase database, @NotNull String sql, Object[] parameters) throws SQLException { SQLiteStatement compiledStatement = getCompiledStatement(database, sql, parameters); compiledStatement.execute(); } public static long performExecuteInsert(@NotNull SQLiteDatabase database, @NotNull String sql, Object[] parameters) throws SQLException { SQLiteStatement compiledStatement = getCompiledStatement(database, sql, parameters); return compiledStatement.executeInsert(); } public static boolean performExecuteUpdateDelete(@NotNull SQLiteDatabase database, @NotNull String sql, Object[] parameters) throws SQLException { SQLiteStatement compiledStatement = getCompiledStatement(database, sql, parameters); return compiledStatement.executeUpdateDelete() > 0; } public static void performExecute(@NotNull SQLiteStatement sqLiteStatement, Object[] parameters) throws SQLException { SQLiteStatement compiledStatement = bindParameters(sqLiteStatement, parameters); compiledStatement.execute(); } public static long performExecuteInsert(@NotNull SQLiteStatement sqLiteStatement, Object[] parameters) throws SQLException { SQLiteStatement compiledStatement = bindParameters(sqLiteStatement, parameters); return compiledStatement.executeInsert(); } public static boolean performExecuteUpdateDelete(@NotNull SQLiteStatement sqLiteStatement, Object[] parameters) throws SQLException { SQLiteStatement compiledStatement = bindParameters(sqLiteStatement, parameters); return compiledStatement.executeUpdateDelete() > 0; } public static Cursor performRawQuery(@NotNull SQLiteDatabase database, @NotNull String sql, Object[] parameters) { return database.rawQuery(sql, convertToStringArray(parameters)); } private static SQLiteStatement getCompiledStatement(@NotNull SQLiteDatabase database, @NotNull String sql, Object[] parameters) throws SQLException { SQLiteStatement sqLiteStatement = database.compileStatement(sql); String[] stringParameters = convertToStringArray(parameters); if (stringParameters != null) { sqLiteStatement.bindAllArgsAsStrings(stringParameters); } return sqLiteStatement; } private static SQLiteStatement bindParameters(@NotNull SQLiteStatement sqLiteStatement, Object[] parameters) { String[] stringParameters = convertToStringArray(parameters); if (stringParameters != null) { sqLiteStatement.bindAllArgsAsStrings(stringParameters); } return sqLiteStatement; } @Nullable private static String[] convertToStringArray(Object[] parameters) { if (parameters == null) { return null; } final int PARAMETERS_LENGTH = parameters.length; if (PARAMETERS_LENGTH == 0) { return null; } String[] stringParameters = new String[PARAMETERS_LENGTH]; for (int i = 0; i < PARAMETERS_LENGTH; i++) { stringParameters[i] = String.valueOf(parameters[i]); } return stringParameters; } }