当前位置: 首页>>代码示例>>Java>>正文


Java SQLiteDatabase.rawQuery方法代码示例

本文整理汇总了Java中android.database.sqlite.SQLiteDatabase.rawQuery方法的典型用法代码示例。如果您正苦于以下问题:Java SQLiteDatabase.rawQuery方法的具体用法?Java SQLiteDatabase.rawQuery怎么用?Java SQLiteDatabase.rawQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.database.sqlite.SQLiteDatabase的用法示例。


在下文中一共展示了SQLiteDatabase.rawQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPageHezb

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public int getPageHezb(int pageNumber) {
    int hezbNumber = 0;
    try {
        SQLiteDatabase db = openDB(MAIN_DATABASE);
        String sql = "select hezb from aya where page = " + pageNumber + " ;";
        Cursor cursor = db.rawQuery(sql, null);

        if(cursor.moveToLast()){
            hezbNumber = cursor.getInt(0);
        }
        cursor.close();
        closeDB(db);
        return hezbNumber;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return hezbNumber;
}
 
开发者ID:fekracomputers,项目名称:QuranAndroid,代码行数:19,代码来源:DatabaseAccess.java

示例2: resetDB

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void resetDB() {
    SQLiteDatabase db = this.getWritableDatabase();
    // query to obtain the names of all tables in your database
    Cursor c = db.rawQuery("SELECT name FROM sqlite_master WHERE type='table'", null);
    List<String> tables = new ArrayList<>();

    // iterate over the result set, adding every table name to a list
    while (c.moveToNext()) {
        tables.add(c.getString(0));
    }

    // call DROP TABLE on every table name
    for (String table : tables) {
        String dropQuery = "DROP TABLE IF EXISTS " + table;
        db.execSQL(dropQuery);
    }
}
 
开发者ID:BernhardWebstudio,项目名称:ShadowTravelor,代码行数:18,代码来源:DBHelper.java

示例3: getCount

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public long getCount(Class<?> cls) {
    String tableName = getTableName(cls);
    if (!isExist(tableName))
        return -1;
    SQLiteDatabase db;
    Cursor cursor = null;
    try {
        db = getReadableDatabase();
        cursor = db.rawQuery(String.format("select count(*) from %s", tableName), null);
        cursor.moveToFirst();
        long count = cursor.getLong(0);
        cursor.close();
        return count;
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (cursor != null && !cursor.isClosed()) {
            cursor.close();
        }
    }
    return 0;
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:23,代码来源:DBHelper.java

示例4: getChatMsgById

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public MyChatMsg getChatMsgById(int id) {
		SQLiteDatabase db = this.getReadableDatabase();
		MyChatMsg myChatMsg = new MyChatMsg();
		Cursor cursor;
		cursor = db.rawQuery("select * from " + TABLE_NAME + " where msgID =?",
				new String[] { id + " " });

		myChatMsg.setMsgId(cursor.getInt(cursor.getColumnIndex("msgID")));
		myChatMsg.setFriendId(cursor.getInt(cursor.getColumnIndex("friendId")));
		myChatMsg.setSenderId(cursor.getInt(cursor.getColumnIndex("sendId")));
		myChatMsg.setMsgContent(cursor.getString(cursor
				.getColumnIndex("content")));

//		Date d = new Date();
//		String string = cursor.getString(cursor.getColumnIndex("publishTime"));
//		SimpleDateFormat sDateFormat = new SimpleDateFormat();
//		try {
//			d = sDateFormat.parse(string);
//		} catch (ParseException e) {
//			e.printStackTrace();
//		}
//		myChatMsg.setChatTime(d);
		myChatMsg.setChatTime(cursor.getString(cursor.getColumnIndex("publishTime")));

		if (cursor.getInt(cursor.getColumnIndex("isNoRead")) == 1) {
			myChatMsg.setNoRead(true);
		} else
			myChatMsg.setNoRead(false);

		return myChatMsg;
	}
 
开发者ID:qizhenghao,项目名称:HiBangClient,代码行数:32,代码来源:ChatMsgDB.java

示例5: getUserChannelByRevokeTxId

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
 * Return a {@code UserChannel} by the transaction identifier of the revoke contract
 * @param revokeTxId the transaction identifier of the revoke contract
 * @return {@code UserChannel} that involves the specified revokeTxId or null if there is no record with the specified revoketxId
 * @throws RegisterException id revokeTxid is null or empty, or an error occurs
 * */
@Override
public UserChannel getUserChannelByRevokeTxId(String revokeTxId) throws RegisterException {

    if(revokeTxId == null || revokeTxId.isEmpty())
        throw new RegisterException("revokeTxId is not valid");

    try {
        try (SQLiteHelperPool.SQLiteDatabaseWrapper sqLiteDatabaseWrapper =
                     androidDataSource.getSQLiteDatabaseWrapper()) {
            SQLiteDatabase db = sqLiteDatabaseWrapper.getSQLiteDatabase();
            try (Cursor cursor = db.rawQuery(
                    "select * from " + SQLiteHelper.TABLE_USER +
                            " where " + SQLiteHelper.USER_CLM_REVOKE_TX_ID + " = ?",
                    new String[]{revokeTxId})) {
                if (cursor.moveToFirst()) {
                    return createUserChannelFromCursor(cursor);
                } else {
                    return null;
                }
            }
        }
    } catch (Throwable t) {
        throw new RegisterException("Exception", t);
    }
}
 
开发者ID:uniquid,项目名称:uidcore-android,代码行数:32,代码来源:Register.java

示例6: getMemberTableCount

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public int getMemberTableCount(String table) {
    int count = 0;
    try {
        String countQuery = "SELECT COUNT(*) as m FROM " + table;
        SQLiteDatabase sq = this.getReadableDatabase();
        Cursor cursor = sq.rawQuery(countQuery, null);
        count = cursor.getInt(0);
        cursor.close();
        sq.close();

    } catch (Exception e) {
        // TODO: handle exception
        //Log.e("GroupDBErro", "GetGroup Count "+e.getMessage());
        e.printStackTrace();
    }
    return count;
}
 
开发者ID:mityung,项目名称:XERUNG,代码行数:18,代码来源:GroupDb.java

示例7: fetchFolders

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private static List<Long> fetchFolders(SQLiteDatabase db) {
    List<Long> folders = new ArrayList<>();
    Cursor cursor = db.rawQuery("SELECT id FROM folders ORDER BY name ASC", null);
    while (cursor.moveToNext()) {
        folders.add(cursor.getLong(0));
    }
    cursor.close();
    return folders;
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:10,代码来源:MigrationTo55.java

示例8: getNodeStoredBytes

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public Cursor getNodeStoredBytes(String nodeID) {
    SQLiteDatabase db = mDbHelper.getReadableDatabase();

    Cursor cursor = db.rawQuery("SELECT * FROM " + NodeReaderContract.NodeStoredBytesEntry.TABLE_NAME + " WHERE " +
            NodeReaderContract.NodeStoredBytesEntry.NODE_ID+" = '"+ nodeID +"' limit 1000", null);

    cursor.moveToFirst();
    return cursor;
}
 
开发者ID:geckogecko,项目名称:storj_hoststats_app,代码行数:10,代码来源:DatabaseManager.java

示例9: isInPlaylist

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public boolean isInPlaylist(int playlistID,String path) {
    SQLiteDatabase db = mDBHelper.getWritableDatabase();
    Cursor cursor = db.rawQuery("select * from playlist_detail where (list_id==?) and (path==?);", new String[]{String.valueOf(playlistID), path});
    boolean value = cursor.moveToFirst();
    cursor.close();
    db.close();
    return value;
}
 
开发者ID:piyell,项目名称:NeteaseCloudMusic,代码行数:9,代码来源:PlaylistModel.java

示例10: requestPeople

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public DataMap<String, Person> requestPeople() {
    SQLiteDatabase db = getReadableDatabase();
    Cursor c = db.rawQuery("SELECT * FROM " + TABLE_PEOPLE, null);
    DataMap<String, Person> events = new DataMap<>();
    if (c.moveToFirst()) do try {
        String id = c.getString(0);
        JSONObject json = new JSONObject(c.getString(1));
        events.put(id, new Person(json));
    } catch (JSONException e) {
        Log.e(TAG, "Failed to parse JSON", e);
    } while (c.moveToNext());
    c.close();
    return events;
}
 
开发者ID:gregoreesmaa,项目名称:minu-poska-android,代码行数:15,代码来源:StuudiumDatabaseHelper.java

示例11: isUserFollowingStreamer

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
 * Determines whether or not the user is currently following a streamer.
 * This is done by looking in the SQLite database
 */
public static boolean isUserFollowingStreamer(String streamername, Context context) {
	SubscriptionsDbHelper mDbHelper = new SubscriptionsDbHelper(context);
	SQLiteDatabase db = mDbHelper.getReadableDatabase();
	String query = "SELECT * FROM " + SubscriptionsDbHelper.TABLE_NAME + " WHERE " + SubscriptionsDbHelper.COLUMN_STREAMER_NAME + "='" + streamername + "';";
	boolean result = false;
	Cursor cursor = db.rawQuery(query, null);
	if(cursor.getCount() > 0) {
		result = true;
	}
	cursor.close();
	db.close();
	return result;
}
 
开发者ID:SebastianRask,项目名称:Pocket-Plays-for-Twitch,代码行数:18,代码来源:Service.java

示例12: getAllTrajectories

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public ArrayList<TupleTrajectory> getAllTrajectories()
{
    ArrayList<TupleTrajectory> listOfTrajectories = new ArrayList<TupleTrajectory>();

    SQLiteDatabase db = getWritableDatabase();
    String query = "SELECT * FROM " + TABLE_PENDING_TRAJECTORY ;
    Cursor c = db.rawQuery(query, null);

    while(c.moveToNext())
    {
        String jsonString = c.getString(c.getColumnIndex(COLUMN_POINT_LIST));

        //temos que converter o jsonString de volta a um String array
        String strSeparator = "__,__";
        String[] jsonArray = jsonString.split(strSeparator);

        JSONArray jsonArrayFinal = new JSONArray();
        //e agora convertemos de volta para um JSON Array
        for(int i = 0; i < jsonArray.length ; i++)
        {
            try {
                JSONObject jsonObject = new JSONObject(jsonArray[i]);
                jsonArrayFinal.put(jsonObject);
            } catch(JSONException e)
            {
                Log.d("Exception", "JSON Exception ");
                e.printStackTrace();
            }
        }
        TupleTrajectory entry = new TupleTrajectory(c.getInt(c.getColumnIndex(COLUMN_DISTANCE)), c.getInt(c.getColumnIndex(COLUMN_POINTS_EARNED)), c.getLong(c.getColumnIndex(COLUMN_TRAVEL_TIME)),jsonArrayFinal,c.getInt(c.getColumnIndex(COLUMN_ID)), c.getString(c.getColumnIndex(COLUMN_DATE)));
        listOfTrajectories.add(entry);
    }

    db.close();
    c.close();

    return listOfTrajectories;
}
 
开发者ID:carlosfaria94,项目名称:UbiBike-client,代码行数:39,代码来源:MyDBHandler.java

示例13: isDownloadRequired

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public boolean isDownloadRequired() {
    final SQLiteDatabase sqldb = mHelper.getReadableDatabase();
    Cursor cur = sqldb.rawQuery("SELECT Count(*) FROM "
            + DownloadColumns.TABLE_NAME + " WHERE "
            + DownloadColumns.STATUS + " <> 0", null);
    try {
        if (null != cur && cur.moveToFirst()) {
            return 0 == cur.getInt(0);
        }
    } finally {
        if (null != cur)
            cur.close();
    }
    return true;
}
 
开发者ID:SlotNSlot,项目名称:SlotNSlot_Android,代码行数:16,代码来源:DownloadsDB.java

示例14: getCrashById

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public Crash getCrashById(int id) {
  SQLiteDatabase readableDatabase = getReadableDatabase();
  Cursor cursor = readableDatabase.rawQuery(CrashTable.selectById(id), null);
  Crash crash = null;

  if (isCursorPopulated(cursor)) {
    crash = toCrash(cursor);
    cursor.close();
    readableDatabase.close();
  }

  return crash;
}
 
开发者ID:ajitsing,项目名称:Sherlock,代码行数:14,代码来源:SherlockDatabaseHelper.java

示例15: getCount

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public Long getCount(){

        String sql = "select count(*) from "+Task.TABLE;
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        Cursor cursor = db.rawQuery(sql, null);
        cursor.moveToFirst();
        long count = cursor.getLong(0);
        cursor.close();
        return count;

    }
 
开发者ID:AndroidNewbies,项目名称:Sanxing,代码行数:12,代码来源:TaskRepo.java


注:本文中的android.database.sqlite.SQLiteDatabase.rawQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。