memtrip / SQLKing

SQLKing is an Android SQLite ORM powered by an annotation preprocessor, tables are defined by Table annotations and CRUD classes expose an expressive api for executing SQLite queries. @memtrip
Other
21 stars 9 forks source link

build of INNER join SQL text is missing whitespace #11

Closed Trellian closed 8 years ago

Trellian commented 8 years ago

Hi Sam,

I'm getting an error on trying to execute a query with some nested joins. An SQLite exception is thrown as follows:

ERR: exMsg=no such column: TblMapVisitor2Entry.visitor_idINNER (code 1): ,
 while compiling: SELECT TblEntry.id,
 TblEntry.synch_status,
 TblEntry.synch_date,
.. (omitted for clarity).

The query code is:

        TblEntry[] entries =
            Select.getBuilder()
                .join (
                        innerJoin (
                                TblMapVisitor2Entry.class,
                                innerJoin (
                                          TblVisitor.class,
                                          on("TblVisitor.id", "TblMapVisitor2Entry.visitor_id"
                                          )
                                ),
                                on("TblMapVisitor2Entry.entry_id", "TblEntry.id")
                               ),
                      innerJoin (
                                TblMapVehicle2Entry.class,
                                innerJoin (
                                          TblVehicle.class,
                                          on("TblVehicle.id", "TblMapVehicle2Entry.visitor_id")
                                          )
                                )
                     )
                .orderBy(Q.TblEntry.ENTRY_DATE, OrderBy.Order.DESC)
                .limit(1, 10)
                .execute(TblEntry.class, ScanDB.sqlProvider);

It looks like a simple case of the INNER clause just not getting some whitespace in front of it. Can you help here?

Thanks, Adrian

Trellian commented 8 years ago

I fixed it as follows:

@@ -245,11 +245,12 @@ public class ClauseHelper {

         for (Join join : joins) {
             SQLQuery sqlQuery = resolver.getSQLQuery(join.getTable());
             String tableName = sqlQuery.getTableName();

-            stringBuilder.append(getJoinType(join))
+            stringBuilder.append(" ")
+                    .append(getJoinType(join))
                     .append(" ")
                     .append(tableName)
                     .append(" ")
                     .append(getClause(join.getClauses()));
samkirton commented 8 years ago

could you make a pull request for this mate?

Cheers, Sam

samkirton commented 8 years ago

Fixed by @Trellian