我在我的项目中使用ActiveAndroid作为ORM系统,我使用这行代码进行Query over database
List<Chats> s = new Select()
.from(Chats.class)
.where(col_conversation + " = ? and " + col_sender + " = ? and " + col_body + " = ?",conversation.getId(),sender.getId(),body) .execute();
Run Code Online (Sandbox Code Playgroud)
但它获取0行作为结果.我确信我在数据库中有这样的行.
如何在ActiveAndroid中添加两列唯一约束?我试图添加2.sql并增加数据库版本,但它似乎没有正确更新(可能是因为我重新安装应用程序?).无论如何,有没有办法添加一些注释,我可以在ActiveAndroid中应用两列唯一约束?
<meta-data android:name="AA_DB_NAME" android:value="Diggecard.db" />
<meta-data android:name="AA_DB_VERSION" android:value="2" />
Run Code Online (Sandbox Code Playgroud)

我只是尝试使用ActiveAndroid.从下面的教程在这里,我设置的一切.我添加了清单条目:
应用程序android:name ="com.activeandroid.app.Application"...
Run Code Online (Sandbox Code Playgroud)meta-data android:name="AA_DB_NAME" android:value="MyDb.db" meta-data android:name="AA_DB_VERSION" android:value="1"
并创建了我的模型类:
package com.mycomp.Model;
import org.joda.time.LocalDate;
import org.odata4j.core.Guid;
import com.activeandroid.Model;
import com.activeandroid.annotation.Column;
import com.activeandroid.annotation.Table;
@Table(name = "Table1")
public class Table1 extends Model
{
@Column(name = "Custom_ID")
public Guid Custom_ID;
@Column(name = "Name")
public String Name;
@Column(name = "Usr_type")
public int Usr_type;
@Column(name = "BDate")
public LocalDate BDate;
public MyEnum UserGroup;
public Table1()
{
super();
}
public Table1(String name, LocalDate date, Guid custom_id,
MyEnum userGroup)
{
super();
Name = name;
BDate …Run Code Online (Sandbox Code Playgroud) 我将东西存储在sqlite数据库中.它的一个属性是颜色.当我显示这个时,我想做
objLinearLayout.setBackgroundColor(some_int)
Run Code Online (Sandbox Code Playgroud)
通常我会使用R.color.red代替some_int.但是,我坚持使用颜色,我认为每次运行应用程序时R文件都会生成一个新的红色ID,这使得该方法不可行.我可以存储字符串表示,如"red",并在我的java代码中检查颜色字符串并应用正确的R.color,但这看起来很难看.有办法吗?
我是ActiveAndroid的新手,我一直在查询数据库.请帮我解决一下图书馆execute()和executeSingle()方法之间的区别ActiveAndroid?
这两种方法都用于查询数据库,但我没有得到何时使用前者以及何时使用后者?
我正在使用 SQLite 并提供id要检索的值列表。但是,这些id值的顺序很重要,我想以相同的顺序检索记录。
例如,
SELECT
*
FROM
todos
WHERE
todos.id in ( 1, 3, 2, 4 )
Run Code Online (Sandbox Code Playgroud)
这将返回:
1
2
3
4
Run Code Online (Sandbox Code Playgroud)
但我希望它以与提供的id值相同的顺序返回,如下所示:
1
3
2
4
Run Code Online (Sandbox Code Playgroud)
我已经看到了 MySQL 和 PostgreSQL 的答案,但没有看到 SQLite 的答案。
我正在尝试使用ActiveAndroid来处理我的应用程序中的数据库.
这是我的模型类:
package ro.adrian.trivia.datamodel;
import java.io.Serializable;
import ro.adrian.trivia.database.TriviaSQLiteHelper;
import com.activeandroid.Model;
import com.activeandroid.annotation.Column;
import com.activeandroid.annotation.Table;
@Table(name = TriviaSQLiteHelper.TABLE_USERS)
public class User extends Model implements Serializable, Comparable<User>{
/**
*
*/
private static final long serialVersionUID = 1L;
@Column(name = TriviaSQLiteHelper.COLUMN_USER_NAME)
private String username;
@Column(name = TriviaSQLiteHelper.COLUMN_FIRST_NAME)
private String first_name;
@Column(name = TriviaSQLiteHelper.COLUMN_LAST_NAME)
private String last_name;
@Column(name = TriviaSQLiteHelper.COLUMN_PASSWORD)
private String password;
public User(){
super();
this.username="";
this.first_name="";
this.last_name="";
this.password="";
}
public User(String username, String password, String firstName, String lastName){
super();
this.username = username; …Run Code Online (Sandbox Code Playgroud) 嗨,大家好,所以我正在尝试测试如何在android中使用数据库作为我的一个类的一部分,但我对这两个都很新,所以我在网上发现的大多数帮助都有点过头了.
我想知道我是如何更新,并从表中删除.目前我有:
wk item = new wk();
item.name = "okay1";
item.save();
Run Code Online (Sandbox Code Playgroud)
这增加了一个项目.
它在我的数据库中
public class wk extends Model {
Table(name = "ToDoItems")
@Column(name = "Name")
Run Code Online (Sandbox Code Playgroud)
但我试着跑
new Delete().from(wk.class).where("Name = ?",2).execute();
Run Code Online (Sandbox Code Playgroud)
我假设在Name的数据库中删除了2的值,但它似乎什么也没做?我试过了
new Delete().from(wk.class).execute();
Run Code Online (Sandbox Code Playgroud)
哪个肯定会删除我的表,所以我知道它可以删除,但我只想删除一个值.
我希望能够删除那个okay1值.
我有一节课:
@Table(name = "Control")
public class Control extends Model{
@Column
private String name;
[...]
@Column
private Map<String, Object> properties;
}
Run Code Online (Sandbox Code Playgroud)
我在这堂课中有其他领域,但我在这里只写了那些足以表明我的问题的东西.
我有一个关于插入的例外:
09-14 22:11:34.542: E/SQLiteLog(11482): (1) table Control has no column named properties
Run Code Online (Sandbox Code Playgroud)
对象可以是String []或String.
如果我不将@Column放在HashMap数据上,那么一切都"好",只有它们没有存储的问题.
所以我的问题是如何解决存储这个hashmap的问题.
我的数据来自API,它总是具有相同的属性:
controls: [
{
bundle: "CloseButton",
frame: "0,0,25,25"
},
{
referenceKey: "AccelerationGyro",
name: "Acceleration Sensor",
bundle: "Gyro",
properties: {
axis: "Z"
observedKey: "brakeState",
requiedValue: "1"
},
channels: {
CH: "Acceleration"
}
},
{
referenceKey: "SteeringGyro",
name: "Steering Sensor",
bundle: "Gyro",
properties: {
axis: …Run Code Online (Sandbox Code Playgroud) 我在AndroidManifest.xml上配置了ActiveAndroid,如下所述:
<application
android:name="com.xxx.xxxx.XXXApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
<meta-data
android:name="AA_DB_NAME"
android:value="MyDB.db" />
<meta-data
android:name="AA_DB_VERSION"
android:value="2" />
...
</application>
Run Code Online (Sandbox Code Playgroud)
申请类:
public class XXXApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
ActiveAndroid.initialize(this);
}
}
Run Code Online (Sandbox Code Playgroud)
模式类是:
@Table(name = "Routes")
public class Route extends Model {
...
public static List<Routes> all(){
return new Select().from(Route.class).execute();
}
}
Run Code Online (Sandbox Code Playgroud)
Ps:我按照文档:https: //github.com/pardom/ActiveAndroid/wiki/Getting-started
当调用Routes.all()时出现此错误:
试图在无准备的类'Lbr/com/xxx/xxx/xxxx/models/Route;'中执行代码
完整堆栈是:
03-08 16:41:56.505: E/dalvikvm(23688): ERROR: tried to execute code in unprepared class 'Lbr/com/xxx/xxx/xxxx/models/Route;' (5)
03-08 16:41:56.505: I/dalvikvm(23688): "main" prio=5 tid=1 RUNNABLE
03-08 …Run Code Online (Sandbox Code Playgroud) 我是Android开发人员的新手,所以我使用ActiveAndroid来管理数据库,我在使用带有Date变量的查询时遇到了麻烦,我有:
From fromQuery = new Select().from(Shift.class);
//It doesn't matter what currentShiftDates do.
CurrentShiftDates currentShiftDates = new CurrentShiftDates();
fromQuery = fromQuery.where("startDate > ? and startDate < ?",currentShiftDates.startDate,
currentShiftDates.endDate);
return fromQuery.execute();
Run Code Online (Sandbox Code Playgroud)
我已经读过查询需要将参数作为long值传递,所以我尝试使用.getTime():
fromQuery = fromQuery.where("startDate > ? and startDate < ?",currentShiftDates.startDate.getTime(), currentShiftDates.endDate.getTime());
Run Code Online (Sandbox Code Playgroud)
但它仍然无效.
我做错了什么?