select * where abc like "xxx" works, ...where abc='xxx' fails

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

select * where abc like "xxx" works, ...where abc='xxx' fails

Doug
I am using Sqlite under QT 5.12.0.

 

Why does the "=" query fail and the "like" query work? There are no
wildcards involved.

 

I create the table this way:

 

QString sqlcreate = QLatin1String(

  "CREATE TABLE songfiletable ("

    "songfile_id INTEGER PRIMARY KEY,"

    "dancename TEXT"

  ");"  );

 

I populated the table this way with dancename=QLatin1String("Waltz"):

 

QString sqlinsert = QLatin1String(

    "INSERT INTO songfiletable ("

    "dancename"

    ") VALUES(?);");

  queryinsert.prepare(sqlinsert);

  queryinsert.addBindValue(dancename.toUtf8());

 

The query that works for dancename="Waltz" is this (with 'like'):

        QByteArray dn = d->dance_name.toUtf8();

        QByteArray filter = "(dancename like '" + dn + "')";

 

The query that fails for dancename="Waltz" is this:

        QByteArray dn = d->dance_name.toUtf8();

        QByteArray filter = "(dancename='" + dn + "')";

 

The behavior is the same in Sqlite command line. There are no
wildcards involved.

 

I have simplified the table and the queries to a single column for
this message. The actual table has 22 columns.

 

Why does the "=" query fail and the "like" query work?

 

Regards, Doug

 

 

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: select * where abc like "xxx" works, ...where abc='xxx' fails

Simon Slavin-3
On 4 Jun 2019, at 12:46am, Doug <[hidden email]> wrote:

> Why does the "=" query fail and the "like" query work?

To help us investigate ...

Which version of SQLite is this ?  You can use

    SELECT sqlite_version();

to find out.

What do you mean by 'work' and 'fail' ?  Are you referring to an error code ?

Can you add a debug line to your code so that just before applying the filter it outputs the same text to a log ?  Just to check whether '.toUtf8()' does what you think it's doing.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: select * where abc like "xxx" works, ...where abc='xxx' fails

Keith Medcalf
In reply to this post by Doug

>Why does the "=" query fail and the "like" query work? There are no
>wildcards involved.

>The behavior is the same in Sqlite command line. There are no
>wildcards involved.

sqlite> create table songfiletable (
   ...> songfile_id integer primary key,
   ...> dancename text
   ...> );
sqlite> insert into songfiletable (dancename) values ('Waltz');
sqlite> select * from songfiletable where dancename like 'Waltz';
1|Waltz
sqlite> select * from songfiletable where dancename = 'Waltz';
1|Waltz

Works for me.  Perhaps your database does not contain what you believe it does ... or you have some indexes on dancename that you are not disclosing

---
The fact that there's a Highway to Hell but only a Stairway to Heaven says a lot about anticipated traffic volume.


>-----Original Message-----
>From: sqlite-users [mailto:sqlite-users-
>[hidden email]] On Behalf Of Doug
>Sent: Monday, 3 June, 2019 17:47
>To: [hidden email]
>Subject: [sqlite] select * where abc like "xxx" works, ...where
>abc='xxx' fails
>
>I am using Sqlite under QT 5.12.0.
>
>
>
>
>
>
>I create the table this way:
>
>
>
>QString sqlcreate = QLatin1String(
>
>  "CREATE TABLE songfiletable ("
>
>    "songfile_id INTEGER PRIMARY KEY,"
>
>    "dancename TEXT"
>
>  ");"  );
>
>
>
>I populated the table this way with dancename=QLatin1String("Waltz"):
>
>
>
>QString sqlinsert = QLatin1String(
>
>    "INSERT INTO songfiletable ("
>
>    "dancename"
>
>    ") VALUES(?);");
>
>  queryinsert.prepare(sqlinsert);
>
>  queryinsert.addBindValue(dancename.toUtf8());
>
>
>
>The query that works for dancename="Waltz" is this (with 'like'):
>
>        QByteArray dn = d->dance_name.toUtf8();
>
>        QByteArray filter = "(dancename like '" + dn + "')";
>
>
>
>The query that fails for dancename="Waltz" is this:
>
>        QByteArray dn = d->dance_name.toUtf8();
>
>        QByteArray filter = "(dancename='" + dn + "')";
>
>
>
>
>
>
>I have simplified the table and the queries to a single column for
>this message. The actual table has 22 columns.
>
>
>
>Why does the "=" query fail and the "like" query work?
>
>
>
>Regards, Doug
>
>
>
>
>
>_______________________________________________
>sqlite-users mailing list
>[hidden email]
>http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users



_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users