0

Ormlite 和 Android/Sqlite 有一些问题,所以任何帮助表示赞赏。数据库结构为

"CREATE TABLE [jobTasks](" +
        "[JobTaskID] varchar(50) NOT NULL PRIMARY KEY DEFAULT (newid())," +
        "[JobID] varchar(50) NOT NULL," +
        "[EnumTaskType] Real," +
        "[TaskID] varchar(50)," +
        "[TaskOrder] SmallInt," +
        "[TaskDescription] NVarChar (50) ," +
        "[EnumTaskStatus] Real," +
        "[EnumTaskQualifier] Real," +
        "[IsTaskQualifierForced] Bit," +
        "[CompletedBy] NVarChar (50)," +
        "[CompletedOn] DateTime," +
        "[CompletedOnOffset] NVarChar (6)," +
        "[JobAssetID] varchar(50),[wadtDeleted] Bit NOT NULL DEFAULT ((0))," +
        "[WadtModifiedBy] NVarChar (15)," +
        "[WadtModifiedOn] DateTime," +
        "[WadtModifiedOnDTOffset] NVarChar (6)," +
        "[WadtRowID] varchar(50) DEFAULT (newid())," +
        "[ParentJobTaskID] varchar(50)," +
        "[Rowguid] varchar(50) NOT NULL DEFAULT (newid())," +
        "SyncDeleted Bit NOT NULL DEFAULT ((0))," +
        "FOREIGN KEY(JobID) REFERENCES jobJob(jobID)," +
        "FOREIGN KEY(enumTaskType)  REFERENCES enumTaskType(enumTaskType)," +
        "FOREIGN KEY(TaskID) REFERENCES cfgWorkFlowTasks(TaskID)," +
        "FOREIGN KEY(enumTaskStatus) REFERENCES enumTaskStatus(enumTaskStatus))"

查询是

QueryBuilder<JobParentTask, String> qb =
    _databaseContext.JobParentTasks().queryBuilder();
qb.orderBy(JobParentTask.TASKORDER, true);
qb.where().eq(JobParentTask.JOBID, id).and()
     .isNull(JobParentTask.PARENTJOBTASKID);
PreparedQuery<JobParentTask> preparedQuery = queryBuilder.prepare();
CloseableIterator<JobParentTask> iterator
    =_databaseContext.JobParentTasks().iterator(jobParentTaskPreparedQuery);
while (iterator.hasNext()) {
    parentTasks.add(iterator.next());
}

抛出以下错误

 unrecognized token: "6B582835": , while compiling:
 SELECT * FROM `jobTasks` WHERE
 `JobID` = 6B582835-5A79-E011-A5E4-005056980009 AND `ParentJobTaskID` IS NULL )
 ORDER BY `TaskOrder` 

如果我将 id 作为字符串值传递,为什么它不会在查询中显示?

抛出的最终错误是

java.sql.SQLException: Could not build prepared-query iterator for class
conx.Entities.JobParentTask

我认为这与原始错误有关?

提前致谢

4

2 回答 2

1

会羞愧地低下头。JOBID 被关联为错误列的列名注释。

于 2011-07-27T05:58:56.890 回答
0

嗯。我怀疑你有一个现有的数据库表,你试图匹配一个 Java 类?JobID您的 Java 类中的字段是否有可能不是字符串,而是意外地是整数?

eq(JobParentTask.JOBID, id)方法应该查看里面的字段JobParentTask,看看它是一个String需要转义的。这是 ORMLite 中已经工作了一段时间的核心代码。

JobParentTask您可以在 JobID 字段周围发布定义吗?

如果您仍然遇到问题,立即解决方法是使用“Select Args”:

http://ormlite.com/docs/select-arg

就像是:

SelectArg jobIdArg = new SelectArg(id);
queryBuilder.where().eq(JobParentTask.JOBID, jobIdArg).and()...

然后构造的查询使用 ? 并使用 SQL 注入参数。

于 2011-07-21T16:49:34.063 回答