Strange SQLite "message"

in a SWIFT app I execute this SQLite statement

SELECT superclass 
FROM objects 
WHERE objtype='C' AND objName='Class1' AND superclass<>''

and Xcode issues this warning at RUNTIME

misuse at line 35812 of [1b37c146ee]

The error message returned by SQLite is
SQLite Error [0] Ok.

In this particular instance I expect 0 records to be returned, and the program runs properly, it just issues this as a WARNING, not an ERROR

any ideas?

There are no threads, all SQLite statements are executed in series, and only after previous one are completed, there are many SQL queries in the app and this is the only one that issues this warning… all other operate silently as expected.

why are you using <> ?

as opposed to what
The non-equals operator can be either != or <>

you’re right, it shouldn’t happen, but sqlstudio is crashing on field<>'' vs field!='' and i don’t know if it’s related.

maybe it’s worth exploring what sql statements do work at that line? Or checking what library is being used?

<> and != returned the same warning

this app contains a few dozen or more SQL statements, this is the only one with this warnig

the SQLite library is the one supplied by Apple [import SQLite3]

SQLite version: 3.43.2

I would evade to superclass NOT LIKE ‘’ or NOT EXIST

no diff

Is objtype supposed to be camel-cased like objName?

So you do have other queries that return no records and don’t issue the warning?

If so, and if superclass is not defined NOT NULL, then maybe Swift/Xcode is warning about using not equal with Null values?

have you got an on disk db you can just fire up sqlite from the command line & try that statement ?

I cannot think of any reason that should generate a warning of that kind
Sqlite is VERY forgiving

If I run this in my sqleditor it is fine, but then as noted above this is a WARNING, not an error

superclass is NOT defined as “Not Null” , but then ‘’ is not null

‘’ != null

objtype is defined in the DDL as ‘objType’, but then SQLite is not case sensitive when it comes to field names, and if it were then a ERROR would be issued not only on this query, but on dozens of other also in this app

Everything is <> Null, even Null! The only expression that will return True when comparing to a Null value is “is” (and “is not”):

superclass is not null

But, of course, empty strings are also not null. Whenever I have a column that can contain Nulls and I’m looking for those that have no value, I use Coalesce().

But in this case you’re not looking for empty values, but for non-empty values, so it doesn’t matter. But what I’m getting at is maybe Swift/Xcode recognizes that you’re comparing against possibly null values and is attempting (poorly) to warn about the pitfalls of doing so. Especially if running the same query from the sqlite3 shell gives no warning.

2 Likes

that same basic syntax “<>‘’” is used in many other queries… Trust me I have done my due dilegence on “what is not the same”

and I realize the difference between “IS NOT NULL” and “<>NULL”

sqlite does NOT treat <> null the same as “is not null”
this is in macOS terminal using the sqlite3 command

sqlite> create table foo(id integer primary key, value text) ;
sqlite> insert into foo(id) values(1) ;
sqlite> insert into foo(id,value) values(2,'') ;
sqlite> insert into foo(id,value) values(3,'abc') ;
sqlite> select * from foo where value <> null ;
sqlite> select * from foo where value is not null ;
2|
3|abc
sqlite> 

NOTE <> null gets NO results where is not does

not sure why the subject of NULL keeps popping up, this database does NOT contain null values, blank values? yes, but that is not the same as NULL

Are you using this query as if it was a prepared statement, with or without finalising?
How exactly do you execute it?

Only because it seems like there just isnt any reason that the warning should be coming up at all
If the columns arent null, and always have a value (even if it is an empty string) its hard to imagine why this warning shows up
Does this warning show up only when running ?
Can you stop at the offending line of code and investigate ?
Just seems really odd

“hard to imagine” I agree, which is why I brought it up here :slight_smile:
Show only when running? Not sure how it could appear at any other tiime???
Other than the fact I located the offending line by inserting “print statements” before and after, and that the execution returns a 0 error value, not sure what else could be investigate

 let SQL = "SELECT superclass FROM \(objectTABLE) WHERE objtype='C' AND objName='\(windowNAME)' AND superclass!=''"
print(SQL)
let rs = DB.SQLSelect(SQL)
<<<--- warning appears here
print(DB.ErrorMessage)
 print("done\n")
SELECT superclass FROM objects WHERE objtype='C' AND objName='Class1' AND superclass!=''
misuse at line 35812 of [1b37c146ee]
SQLite Error [0] Ok.
done

and no idea what/where line 35812 is

Which is why I assumed this warning is occuring in the Swift/Xcode framework/library/driver/whatever. It’s either an outright bug, or an incomplete “warning” system (so still a bug). The word “misuse” indicates a comparison against a “proper use”, which is why I brought up the case of nulls.

It’s simple to see if I’m right. Make the column NOT NULL. Doesn’t matter if it currently has no null values if the framework is only looking at the table definition.

Or try changing the query. Select * instead of just superclass, just to see what happens.

You could also post the actual table structure. Maybe someone will see something there.

  • SELECT * , same issue

changing DDL to

CREATE TABLE objects ( objID Integer NOT NULL DEFAULT 0,
objName Text NOT NULL COLLATE NOCASE DEFAULT '',
instance Integer NOT NULL DEFAULT - 1,
objType Text NOT NULL COLLATE NOCASE DEFAULT '',
superclass Text NOT NULL COLLATE NOCASE DEFAULT '',
parent Integer NOT NULL DEFAULT 0)

no change