1

Since you updated the library to Int64 I can't compile my code anymore. I keep getting problems with update methods like this:

let id = Expression<String>("id")
let categoryId = Expression<Int64>("categoryId")
let languageId = Expression<String>("languageId")
let name = Expression<String>("name")
let thumb = Expression<Blob?>("thumb")
let modificationDate = Expression<String>("modificationDate")
let isCurrent = Expression<Int64>("isCurrent")
let isLocal = Expression<Int64>("isLocal")
let needsUpdate = Expression<Int64>("needsUpdate")
let progress = Expression<Double>("progress")

let brochureToUpdate = table.filter(id == brochure.pdfId).update(isLocal <- Int64(brochure.isLocal), needsUpdate <- Int64(brochure.needsUpdate)).changes

I have changed all Expression from Expression to Expression, and all Int that are bind to Expression are Int64.

I get: Could not find member 'changes' if I remove changes i get : Could not find member 'update'

user2496373
  • 105
  • 2
  • 8

3 Answers3

1

I can't see what brochure is but I get the same result if brochure.pdfId returns anything other than a String.

Swift errors can be hard to deduce when you have a chained expression. One way to troubleshoot is to break it into multiple steps:

let filter = table.filter(id == brochure.pdfId) // fails
filter.update(
    isLocal <- Int64(brochure.isLocal),
    needsUpdate <- Int64(brochure.needsUpdate)
).changes

That way, you get a much more helpful error. If, for example, brochure.pdfId returns an Int: Binary operator '==' cannot be applied to operands of type 'Expression<String>' and 'Int'.

Changing to the following should hopefully allow things to compile:

table.filter(id == String(brochure.pdfId))

Other thoughts...

Is there a reason you switched to Int64 everywhere? You should still be able to use Int anywhere that you don't need 64-bit precision. You can even use types like Bool for things that are boolean values:

let isCurrent = Expression<Bool>("isCurrent")
let isLocal = Expression<Bool>("isLocal")

With an extension, you can even use NSDate:

let modificationDate = Expression<NSDate>("modificationDate")
stephencelis
  • 4,954
  • 2
  • 29
  • 22
  • Thanks Stephen, if I don't convert to Int64 I don't get any compile errors, but then at runtime, it crashes because incompatibility between Int and Int64. – user2496373 Mar 05 '15 at 09:44
  • As I commented elsewhere. Int64 is required for automatic conversations using the raw API. For real performance, you should skip the array entirely, though, and use the cursor for row access, which does convert to Bool and Int: `while statement.step() { var isLocal = statement.row[6] as Bool }`. – stephencelis Mar 05 '15 at 16:20
1

Thanks Stephen,

using

while statement.step() {
    .....
}

did the trick. I can use Bool and doesn't complain about Int.

I did see while statement.step() on the documentation, is an undocumented features?

user2496373
  • 105
  • 2
  • 8
  • It was added recently. The raw API is underdocumented at the moment in preference of the expression layer, but more documentation will be available in the future. Please note that `stmt.row` access will never fail (`NULL` always becomes `false`, `0`, `""`, a Blob with zero bytes, etc.), which can be a blessing or a curse. – stephencelis Mar 05 '15 at 17:12
0

I tried this:

    let brochureToUpdate = table.filter(id == "dfdf")
    brochureToUpdate.update(
        isLocal <- Int64(brochure.isLocal),
        needsUpdate <- Int64(brochure.needsUpdate)
    ).changes

I get 'Statement' does not have a member named 'changes'

If I try this:

    let brochureToUpdate = table.filter(id == "dfdf")
    brochureToUpdate.update(
        isLocal <- Int64(brochure.isLocal),
        needsUpdate <- Int64(brochure.needsUpdate)
    )

Cannot invoke 'update' with an argument list of type '($T9, $T17)'

both brochure.isLocal and brochure.needsUpdate are Int64

As I said on the comment, if I don't use Int64 but Int I don't get any compile error, but at run time it crashes here:

  for row in statement{
      var isLocal = row[6] as Int
  }
user2496373
  • 105
  • 2
  • 8
  • Try breaking the expression down further: `let brochureIsLocal = Int64(brochure.isLocal); let brochureNeedsUpdate = Int64(brochure.needsUpdate); let localSetter = isLocal <- brochureIsLocal; let updateSetter = needsUpdate <- brochureNeedsUpdate; brochureToUpdate.update(localSetter, updateSetter)`. Swift 1.2 has better error messaging, but it's still not perfect. As for the crash: the only place that you need to change to use Int64 is the raw SQL API. The expression (type-safe layer) can still use Int (or Bool, or NSDate). – stephencelis Mar 05 '15 at 16:09