Boolean values in variable, tclsqlite3

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

Boolean values in variable, tclsqlite3

Gilles Pérez

Hello,

If I run the attached script (results I see in attached text), one can see a problem with true and false in variables. If I write true or false directly, no problem, sqlite store a 1 or a 0.

But if a put them in a variable, sqlite always store them as strings "true" or "false".

How to achieve a correct result with a $value or :value without prefiltering values “true” or “false”?

Thank you,

Gilles.


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

results.txt (984 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Boolean values in variable, tclsqlite3

Gilles Pérez
As the script got removed, here it is:

package require sqlite3

proc main {} {

        puts "sqlite3 version: [
                exec sqlite3 -version
        ]"
        sqlite3 db :memory:

        puts "libsqlite3 version: [
                db version
        ]"

        db eval {
                CREATE TABLE test (
                        id INTEGER PRIMARY KEY,
                        b BOOLEAN NOT NULL DEFAULT false
                );
        }

        db2 eval {
                INSERT INTO test (b) VALUES (true);
        }

        display

        db2 eval {
                INSERT INTO test (b) VALUES (:tvalue);
        }

        display

        db2 eval "
                INSERT INTO test (b) VALUES (false);
        "

        display

        db2 eval {UPDATE test SET b = :fvalue WHERE id = 2}

        display
       
        db2 eval {UPDATE test SET b = false WHERE id = 2}

        display
}

proc display {} {
        db eval {
                SELECT * FROM test;
        } values {
                array unset values {\*}
                parray values
                puts ""
        }
        puts ""
}

proc db2 {action req} {
        set tvalue true
        set fvalue false
        puts [string trim $req]
        db $action $req
}

main



2019-07-19 17:02 +02:00, [hidden email] :

>
> Hello,
>
> If I run the attached script (results I see in attached text), one can see a problem with true and false in variables. If I write true or false directly, no problem, sqlite store a 1 or a 0.
>
> But if a put them in a variable, sqlite always store them as strings "true" or "false".
>
> How to achieve a correct result with a $value or :value without prefiltering values “true” or “false”?
>
> Thank you,
>
> Gilles.
>
>
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
>
> *Pièces jointes:*
>  * results.txt
_______________________________________________
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: Boolean values in variable, tclsqlite3

Richard Hipp-3
On 7/19/19, Gilles Pérez <[hidden email]> wrote:
> set tvalue true

This statement sets the TCL variable "tvalue" to the four-character
string "true", not to a boolean true.
--
D. Richard Hipp
[hidden email]
_______________________________________________
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: Boolean values in variable, tclsqlite3

Gilles Pérez
2019-07-19 19:29 +02:00, [hidden email] :
> On 7/19/19, Gilles Pérez <[hidden email]> wrote:
> > set tvalue true
>
> This statement sets the TCL variable "tvalue" to the four-character
> string "true", not to a boolean true.

Is it possible in Tcl to specify I want a boolean? For now, I “filter” true/false values and I mix $ or : notation with literal I build, but it's not that practical.

Thank you,
Gilles.

--
📌  Envoyé de mon téléphone. Excusez la brièveté.
📌  Sendita per poŝtelefono, pardonu do la koncizon.
_______________________________________________
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: Boolean values in variable, tclsqlite3

Simon Slavin-3
On 19 Jul 2019, at 9:15pm, Gilles Pérez <[hidden email]> wrote:

> Is it possible in Tcl to specify I want a boolean?

You don't want a boolean.  SQLite doesn't understand booleans.  You want integers.  Do this

Constants:
        DB_FALSE = 0, DB_TRUE = 1

I would suggest you don't use names like SQLITE_FALSE because the assumption would be that those are defined in a SQLITE library, but you can use other names.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users