我在Python 2.6.4中使用sqlite3模块来将date时间存储在SQLite数据库中。 插入它非常容易,因为sqlite会自动将date转换为string。 问题是,在阅读它时会返回string,但我需要重build原始的date时间对象。 我该怎么做呢?
我无法弄清楚下划线字符在SQLite语句中的作用。 通配符%可能与大多数其他SQL数据库相同。 那么该死的angular色呢?
以降序显示我的数据的最有效的方法是什么? public String getRank() { String[] rank = new String[]{ KEY_ROWID }; Cursor c = scoreDb.query(DATABASE_TABLE, rank, null, null, null, null, null); //reading information from db. String rankResult = ""; int iRow = c.getColumnIndex(KEY_ROWID); //Cursor looking for column setting equal to these ints. for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) { //Move to first row – where cursor […]
我正在寻找一个关于如何使用SQLite和Android的ORMLite的入门教程。 qucick谷歌search没有产生任何有用的信息。
我正在使用queryfunction,以build立我的表的SQL查询。 有没有办法看到运行的实际查询? 例如logging在什么地方? 到目前为止,我所能做的最好的是使用断点来查看游标的成员mQuery。 我很想自动输出查询。 这个成员当然是不公开的,没有吸气。 只是为了logging,这是一个接受答案的实现。 /** * Implement the cursor factory in order to log the queries before returning * the cursor * * @author Vincent @ MarvinLabs */ public class SQLiteCursorFactory implements CursorFactory { private boolean debugQueries = false; public SQLiteCursorFactory() { this.debugQueries = false; } public SQLiteCursorFactory(boolean debugQueries) { this.debugQueries = […]
使用Linux,我想比较两个具有相同模式的SQLite数据库。 只会有一些差异。 有没有可以输出这些差异的工具? 最好将它们输出到命令行,以便我可以grep / sed它们。 SQLite使用SQL,所以一般的SQL工具也可以。
如何获取Android中使用SQLite查询的行数? 看来我的以下方法不起作用。 public int getFragmentCountByMixId(int mixId) { int count = 0; SQLiteDatabase db = dbOpenHelper.getWritableDatabase(); Cursor cursor = db.rawQuery( "select count(*) from downloadedFragement where mixId=?", new String[]{String.valueOf(mixId)}); while(cursor.moveToFirst()){ count = cursor.getInt(0); } return count; }
我有两个表,名为user_name的同一列,说table_a,table_b。 我想从table_b,column_b_1,column_b2分别复制到table_b1,column_a_1,column_a_2,分别在user_name是相同的,如何在sql语句中做到这一点?
我一直在尝试让我的Android SQLite数据库中的外键工作。 我已经尝试过下面的语法,但它给了我一个closures的力量: private static final String TASK_TABLE_CREATE = "create table " + TASK_TABLE + " (" + TASK_ID + " integer primary key autoincrement, " + TASK_TITLE + " text not null, " + TASK_NOTES + " text not null, " + TASK_DATE_TIME + " text not null, FOREIGN KEY ("+TASK_CAT+") REFERENCES "+CAT_TABLE+" ("+CAT_ID+"));"; […]
在Python 2.5中使用SQLite3,我试图迭代一个列表,并根据项目的名称从数据库中拉取项目的权重。 我尝试使用“?” 参数replacebuild议防止SQL注入,但它不起作用。 例如,当我使用: for item in self.inventory_names: self.cursor.execute("SELECT weight FROM Equipment WHERE name = ?", item) self.cursor.close() 我得到的错误: sqlite3.ProgrammingError:提供的绑定数量不正确。 当前语句使用1,并提供了8。 我相信这是由数据库的初始创build造成的。 我所做的实际创build数据库的模块确实有8个绑定。 cursor.execute("""CREATE TABLE Equipment (id INTEGER PRIMARY KEY, name TEXT, price INTEGER, weight REAL, info TEXT, ammo_cap INTEGER, availability_west TEXT, availability_east TEXT)""") 但是,当我使用不太安全的“%s”replace每个项目名称,它工作得很好。 像这样: for item in self.inventory_names: self.cursor.execute("SELECT weight FROM Equipment […]