如何在Android

时间:2015-09-21 09:54:54

标签: android sqlite android-studio

我正在学习Android我怀疑如何在android Studio中使用外部SQLite Manager(在Firefox中添加)

请说明如何在Sqlite示例中使用两个TABLE NAMES:user table和Admin Table

2 个答案:

答案 0 :(得分:1)

public class SqlLiteDbHelper扩展了SQLiteOpenHelper {

SELECT TOP 1 *
FROM @Temp t 
    CROSS APPLY -- The ordering logic write here
    (
        SELECT
            CASE 
                WHEN (city = 'London' AND ref = 'GBP') THEN 1
                WHEN (city = 'London' AND ref <> 'GBP') THEN 2
                -- Not match at all
            END AS Value
    ) orders
WHERE orders.Value IS NOT NULL
ORDER BY 
    CASE WHEN orders.Value IS NULL THEN 1 ELSE 0 END, 
    orders.Value

答案 1 :(得分:0)

您可以将数据库与表设计等架构放在一起,也可以是表格中的数据

在assets文件夹中为1 mb,当您创建sqlite manager实例时,

从资产复制到data / data / packagename / databases /

首先检查DAtabase是否已使用此代码复制它

private static String DB_PATH = "/data/data/packageName/databases/";
private static String DB_NAME = "dbname.db";

private boolean checkDataBase() {
    SQLiteDatabase checkDB = null;
    try {
        String myPath = DB_PATH + DB_NAME;
        checkDB = SQLiteDatabase.openDatabase(myPath, null,
                SQLiteDatabase.OPEN_READWRITE);
        if(checkDB.getVersion() < DATABASE_VERSION){
            onUpgrade(checkDB, checkDB.getVersion(), DATABASE_VERSION);
        }
    } catch (SQLiteException e) {
    }
    if (checkDB != null) {
        checkDB.close();
    }
    return checkDB != null ? true : false;
}

如果不存在则

private void copyDataBase() throws IOException {
    // Open your local db as the input stream
    InputStream myInput = mContext.getAssets().open(DB_NAME);
    // Path to the just created empty db
    String outFileName = DB_PATH + DB_NAME;
    // Open the empty db as the output stream

    OutputStream myOutput = new FileOutputStream(outFileName);
    // transfer bytes from the inputfile to the outputfile
    byte[] buffer = new byte[1024];
    int length;
    while ((length = myInput.read(buffer)) > 0) {
        myOutput.write(buffer, 0, length);
    }
    // Close the streams
    myOutput.flush();
    myOutput.close();
    myInput.close();

}