Ormlite query help for newbie
Having a few problems with Ormlite and Android/Sqlite so any help appreciated. The database structure is
"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 (n开发者_如何学Pythonewid())," +
"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))"
The query is
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());
}
The following error is thrown
unrecognized token: "6B582835": , while compiling:
SELECT * FROM `jobTasks` WHERE
`JobID` = 6B582835-5A79-E011-A5E4-005056980009 AND `ParentJobTaskID` IS NULL )
ORDER BY `TaskOrder`
If I am passing the id as a string value why does it not show as such in the query?
The final error thrown is
java.sql.SQLException: Could not build prepared-query iterator for class
conx.Entities.JobParentTask
I assume this is related to the original error?
Thanks in advance
Will hang my head in shame. The JOBID was associated as a column name annotation for the wrong column.
Huh. I suspect you have an existing database table that you are trying to match a Java class against? Any chance that the JobID
field in your Java class is not a string but is, by accident, an integer?
The eq(JobParentTask.JOBID, id)
method should look at the field inside of JobParentTask
and see that it is a String
that needs to be escaped. This is core code in ORMLite that has been working for some time.
Can you post the JobParentTask
definition around the JobID field?
If you still are having problems an immediate workaround is to use the "Select Args":
http://ormlite.com/docs/select-arg
Something like:
SelectArg jobIdArg = new SelectArg(id);
queryBuilder.where().eq(JobParentTask.JOBID, jobIdArg).and()...
Then the query that is constructed used a ? and injects the argument using SQL.
精彩评论