我在我的数据库中显示查询数据ListView.我的问题是:我可以从查询中订购数据,然后将这些有序数据存储在我的光标对象中吗?或者我必须订购ListView?
即我可以在以下查询中按名称订购数据吗?
Cursor c = ourDatabase.query(DATABASE_TABLE, columns, KEY_ROWID + "=" + passId, null, null, null, null);
Run Code Online (Sandbox Code Playgroud) 我有一个这样的SQL语句:
INSERT INTO TABLE_3(TABLE_1ID, TABLE_2ID)
SELECT ID FROM TABLE_1 WHERE NAME = '..',
SELECT ID FROM TABLE_2 WHERE NAME = '..';
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我刚收到一个错误
声明...靠近"SELECT":语法错误.
那么如何正确地做到这一点?没有示例如何使用来自两个不同表的两个选项来处理此问题.
这可行:
INSERT INTO TABLE_1(NAME, AGE)
SELECT NAME, AGE FROM TABLE_2 WHERE ID = '..';
Run Code Online (Sandbox Code Playgroud) 我正在使用嵌入式SQLite数据库制作iOS应用程序.所以我在SQLite管理员中创建我的数据库并将其拖到我的Xcode项目中,就像在教程中说的那样.当我尝试打开我的数据库时,我收到此错误:"内存不足".不知道它是否是一个SQLite错误或什么,但我的文件真的很小,以解决内存问题.
这是我的初始化DataBase的代码:
- (id)initWithPath:(NSString *)path {
if (self = [super init]) {
BOOL success;
NSError *error;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *dbPath = [documentsDirectory stringByAppendingPathComponent:@"SoundLib_DB.sqlite"];
if ([fileManager fileExistsAtPath:dbPath] == NO) {
NSString *resourcePath = [[NSBundle mainBundle] pathForResource:@"SoundLib_DB" ofType:@"sqlite"];
[fileManager copyItemAtPath:resourcePath toPath:dbPath error:&error];
}
success = [fileManager fileExistsAtPath:dbPath];
if(!success)
{
NSLog(@"Cannot locate database file '%@'.", dbPath);
}
sqlite3 *dbConnection;
//Here is when I get the error, at trying to …Run Code Online (Sandbox Code Playgroud) 我正在用Python构建一个财务应用程序来对安全价格(以及其他事情)进行时间序列分析.繁重的工作将在Python中完成,主要使用Numpy,SciPy和pandas(pandas有一个SQLite和MySQL的接口).使用Web界面显示结果.将有几百GB的数据.
我很好奇数据库在性能,访问数据(查询)的简易性以及与Python的接口方面有什么更好的选择.我已经看过有关SQLite诉MySQL的一般优缺点的帖子,但我正在寻找更具体的Python应用程序的反馈.
我有以下功能,我试图获取一列中的所有整数并总结它们.不知道该怎么做.
下面的代码不起作用,因为对于测试我在表中放了两行,KEY_HITS列的数字是5和6,总数应该是11但是我得到4作为结果
public int getTotal() {
String[] columns = new String[] { KEY_ROWID, KEY_NAME, KEY_HITS };
Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null,
null, null);
int total = 0;
int iHits = c.getColumnIndex(KEY_HITS);
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
total = total + iHits;
}
return total;
}
Run Code Online (Sandbox Code Playgroud) 我有这个辅助功能:
public bool Delete(String tableName, String where)
{
Boolean returnCode = true;
try
{
this.ExecuteNonQuery(String.Format("delete from {0} where {1};", tableName, where));
}
catch (Exception fail)
{
MessageBox.Show(fail.Message);
returnCode = false;
}
return returnCode;
}
Run Code Online (Sandbox Code Playgroud)
TableName包含"[MyTable]",其中包含"[MyTable ID] ='4ffbd580-b17d-4731-b162-ede8d698e026'",它是表示行ID的唯一guid.
该函数返回true,就像它成功一样,并且没有异常,但是行不会从DB中删除,那是什么?
这是ExecuteNonQuery函数
public int ExecuteNonQuery(string sql)
{
SQLiteConnection cnn = new SQLiteConnection(dbConnection);
cnn.Open();
SQLiteCommand mycommand = new SQLiteCommand(cnn);
mycommand.CommandText = sql;
int rowsUpdated = mycommand.ExecuteNonQuery();
cnn.Close();
return rowsUpdated;
}
Run Code Online (Sandbox Code Playgroud) 我正在使用python脚本,当我尝试从另一个python脚本导入一个类时,我面临导入问题.这是我的python项目文件夹的外观:
Mysql_Main/
checks.py
Analyzer/
config.py
ip.py
op.py
__init__.py
Run Code Online (Sandbox Code Playgroud)
现在我想将两个名为:Config()和Sqlite()的类从config.py导入到checks.py脚本中.我该怎么做?
这是我试过的,但它导致错误!
在checks.py内:
from Analyzer import config
config = config.Config()
sqlite = config.Sqlite()
Run Code Online (Sandbox Code Playgroud)
问题是Config类被正确导入,但Sqlite类没有被导入.它显示错误 - Config实例没有属性'Sqlite'
我一直SQLite在我的应用程序中使用来存储一些要在应用程序中使用的数据.我面临的问题是,如果让我说今天用一些数据填充表格并在应用程序中显示它们,数据仍然存在并且不会丢失.
然而,当我第二天来到并尝试显示我前一天输入的数据时,数据似乎已经丢失(或者可能整个database/tables都被重新创建,我不太确定)
我写的方式database如下:
public class CustomExercisesDB
{
private static final String DB_NAME = "app";
private static final int DB_VERSION = 15;
private static final String ChosenExercises = "ChosenCustExs";
public static final String ChEX_ID = "ChExId";
public static final String Cust_NAME = "CustomName";
public static final String ChEx_NAME = "ChExName";
public static final String ChEx_Weight = "ChExWeight";
public static final String ChEx_Reps = "ChExReps";
public static final String ChEx_Sets = "ChExSets";
private DBHelper …Run Code Online (Sandbox Code Playgroud) 我的光标返回记录两次,即使我将distinct设置为true:
返回myDataBase.query(true,DB_TABLE,new String [] {"rowid as _id",KEY_CONDITIONS},builder.toString(),symptoms,null,null,null,null);
仅供参考,
public Cursor getData(String[] symptoms) {
String where = KEY_SYMPTOMS + "= ?";
String orStr = " OR ";
StringBuilder builder = new StringBuilder(where);
for(int i = 1; i < symptoms.length; i++)
builder.append(orStr).append(where);
return myDataBase.query(true, DB_TABLE, new String[]
{"rowid as _id", KEY_CONDITIONS}, builder.toString(), symptoms, null, null, null, null);
}
Run Code Online (Sandbox Code Playgroud)
或者我尝试更改为rawQuery
return myDataBase.rawQuery("SELECT DISTINCT " + KEY_CONDITIONS + " FROM "
+ DB_TABLE + " " + builder.toString() + symptoms.toString(), null);
Run Code Online (Sandbox Code Playgroud)
我的LogCat说:
03-02 22:57:02.634: …Run Code Online (Sandbox Code Playgroud) 我正在开发一个iPhone聊天应用程序,当我将包含文本的表情符号保存到Sqlite3数据库并将它们重新取回时,我遇到了问题.
或者我想知道无论如何从iPhone的默认键盘(表情符号类型)获得一个笑脸类型的Unicode.