Code Monkey home page Code Monkey logo

Comments (4)

Tybion avatar Tybion commented on June 10, 2024

I just figured that I need to run spatialite_init_ex again.
This is working again, and I also found a null title on the 65th row, so now allow for that ..

do {
    try dbQueue!.inDatabase { db in

        spatialite_initialize()
        var spconnect: OpaquePointer?
        spatialite_init_ex(db.sqliteConnection, &spconnect, 0)  // NOT verbose
        
        let rows = try Row.fetchCursor(db, sql: sql, arguments: [])
        var count = 0
        while let row = try rows.next() {
            count += 1
            MyUtils.Log(TAG, "count=\(count)")
            let fid = row["\(fidcolumn!)"] as Int
            let wkt = row["wkt"] as String
            let title = row["title"] as? String ?? "no title"
            let geom =  try Geometry(wkt: wkt)

from grdb.swift.

groue avatar groue commented on June 10, 2024

Hello again, @Tybion,

A fatal error is the sign that the Swift code, or the database, has to be changed for the program to be correctly formed.

Here, the message "could not decode String from database value NULL" means that you ask the row for a String in the column wkt, but the row contains NULL. There is no such thing as a Swift String that represents the NULL value. NULL is not the same value as the empty string.

From there, there are several possible solutions, depending on the root problem.

  1. If the root problem is that the wkt column contains NULL when it should not, then alter your database schema and add a NOT NULL constraint to wkt. Your program will then fail earlier, when it tries to insert a NULL there, and this is where you will apply the necessary fix.
  2. If the root problem is that the program should filter out NULL wkt values, then alter the query sql with WHERE wkt IS NOT NULL.
  3. If the root problem is that the program should be ready for NULL wkt values, then alter the wkt variable type with: let wkt = row["wkt"] as String?. A NULL value will then be decoded as a nil String? optional. Alternatively, if you want to process NULL just as if it was the empty string: let wkt: String = row["wkt"] ?? "".

When the app starts I get the following, but don't know what is producing this ..

Maps(875,0x202cb3f00) malloc: Unable to set up reclaim buffer (46) - disabling large cache

I don't know what this means.


Final note: I changed the title of the issue so that it can raise the interest of other people who browse the web and search Google for error messages. This question is not about Spatialite, and no issue is personal (as long as we're in the context of support given for free).

from grdb.swift.

Tybion avatar Tybion commented on June 10, 2024

Hello, Gwendal. It seems that you missed reading my second message - this has the answer to the problem in my first message. The question is about spatialite and the solution is to run spatialite_init_ex again. I think it is good if you leave 'spatialite' in the issue name so other spatialite+GRDB users find it when searching.

from grdb.swift.

groue avatar groue commented on June 10, 2024

Oh, I'm sorry @Tybion, you're correct I did not properly read your second message. I have restored spatialite in the title, and I'm happy you could fix your issue. It looks like the issue can be closed!

from grdb.swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.