Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Today is a good day for information-gathering. Read someone else's mail file.


devel / comp.lang.tcl / Re: Help with sqlite statement

SubjectAuthor
* Help with sqlite statementLuc
+- Help with sqlite statementfr
+* Help with sqlite statementGerald Lester
|`* Help with sqlite statementGerald Lester
| `* Help with sqlite statementLuc
|  `- Help with sqlite statementGerald Lester
+- Help with sqlite statementsaitology9
`* Help with sqlite statementRich
 `* Help with sqlite statementLuc
  `- Help with sqlite statementRich

1
Help with sqlite statement

<20221119095522.10f94c88@lud1.home>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10199&group=comp.lang.tcl#10199

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!pgFU3G4+2WW01qgkGGaBqw.user.46.165.242.75.POSTED!not-for-mail
From: no...@no.no (Luc)
Newsgroups: comp.lang.tcl
Subject: Help with sqlite statement
Date: Sat, 19 Nov 2022 09:55:22 -0300
Organization: Aioe.org NNTP Server
Message-ID: <20221119095522.10f94c88@lud1.home>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="58495"; posting-host="pgFU3G4+2WW01qgkGGaBqw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
X-Newsreader: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu)
 by: Luc - Sat, 19 Nov 2022 12:55 UTC

Hello. Very simple question. I think.

foreach i $columns {
blah blah blah,
create list of columns and types,
set eval [list of columns]
}

sqlwrite eval "CREATE TABLE $tablename($eval)"

I am really struggling with that last line. I've tried all kinds of syntax
and every one fails. It seems to me that Tcl interprets the form
$variable(parentheses) as an element of an array. I can only make
it work hard coding the table's name, which is not what I want.

What would the correct way for that be?

You want more code, don't you? Alright.

set datatypes {
Dirname text
Contains int
Data real
X text
Y int
Z real
}

set fe 0
foreach i $datatypes {
append eval " [lindex $datatypes $fe]"
incr fe
append eval " [lindex $datatypes $fe]"
if {[expr $fe + 1] < [llength $datatypes]} {
set eval "$eval,"
} else {set eval "$eval"}
incr fe
}

puts $eval

sqlite3 sqlwrite /path/to/file.db
set tablename "nicetable"
sqlwrite eval "CREATE TABLE $tablename($eval)"

--
Luc
>>

Re: Help with sqlite statement

<4d7e7f3e-75eb-439b-8900-fb635fc6bfc6n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10200&group=comp.lang.tcl#10200

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a0c:e649:0:b0:4c6:1e50:f01c with SMTP id c9-20020a0ce649000000b004c61e50f01cmr10757644qvn.87.1668871051794;
Sat, 19 Nov 2022 07:17:31 -0800 (PST)
X-Received: by 2002:a05:622a:4a1a:b0:39c:b013:3db2 with SMTP id
fv26-20020a05622a4a1a00b0039cb0133db2mr11048299qtb.26.1668871051608; Sat, 19
Nov 2022 07:17:31 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Sat, 19 Nov 2022 07:17:31 -0800 (PST)
In-Reply-To: <20221119095522.10f94c88@lud1.home>
Injection-Info: google-groups.googlegroups.com; posting-host=194.230.161.22; posting-account=aaGzBAoAAADO0Qsz99jkqns7nnqZHQxI
NNTP-Posting-Host: 194.230.161.22
References: <20221119095522.10f94c88@lud1.home>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <4d7e7f3e-75eb-439b-8900-fb635fc6bfc6n@googlegroups.com>
Subject: Re: Help with sqlite statement
From: zaw...@gmail.com (fr)
Injection-Date: Sat, 19 Nov 2022 15:17:31 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2761
 by: fr - Sat, 19 Nov 2022 15:17 UTC

On Saturday, November 19, 2022 at 1:55:30 PM UTC+1, Luc wrote:
> Hello. Very simple question. I think.
>
> foreach i $columns {
> blah blah blah,
> create list of columns and types,
> set eval [list of columns]
> }
>
> sqlwrite eval "CREATE TABLE $tablename($eval)"
>
> I am really struggling with that last line. I've tried all kinds of syntax
> and every one fails. It seems to me that Tcl interprets the form
> $variable(parentheses) as an element of an array. I can only make
> it work hard coding the table's name, which is not what I want.
>
> What would the correct way for that be?
>
>
> You want more code, don't you? Alright.
>
> set datatypes {
> Dirname text
> Contains int
> Data real
> X text
> Y int
> Z real
> }
>
> set fe 0
> foreach i $datatypes {
> append eval " [lindex $datatypes $fe]"
> incr fe
> append eval " [lindex $datatypes $fe]"
> if {[expr $fe + 1] < [llength $datatypes]} {
> set eval "$eval,"
> } else {set eval "$eval"}
> incr fe
> }
>
> puts $eval
>
> sqlite3 sqlwrite /path/to/file.db
> set tablename "nicetable"
> sqlwrite eval "CREATE TABLE $tablename($eval)"
>
> --
> Luc
> >>
Better avoid eval as name of a variable, as eval is a Tcl command.
#one possible way without using lists could be
set description "name1 type 1, name2 type 2"
#then append description to tablename like
append tablename ( $description )
# note the 3 parameters to the append command
sqlwrite eval "CREATE TABLE $tablename"
# you probably want to create variable description from your list variable datatypes, to insert the required comma in SQL-syntax.

Roland Frank

Re: Help with sqlite statement

<tlauki$10hc$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10201&group=comp.lang.tcl#10201

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!JNQqFS25rnmZhNEZ11/SOA.user.46.165.242.75.POSTED!not-for-mail
From: Gerald.L...@KnG-Consulting.net (Gerald Lester)
Newsgroups: comp.lang.tcl
Subject: Re: Help with sqlite statement
Date: Sat, 19 Nov 2022 10:01:21 -0600
Organization: KnG Consulting, LLC
Message-ID: <tlauki$10hc$1@gioia.aioe.org>
References: <20221119095522.10f94c88@lud1.home>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="33324"; posting-host="JNQqFS25rnmZhNEZ11/SOA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.11.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Gerald Lester - Sat, 19 Nov 2022 16:01 UTC

On 11/19/22 06:55, Luc wrote:
> Hello. Very simple question. I think.
>
> foreach i $columns {
> blah blah blah,
> create list of columns and types,
> set eval [list of columns]
> }
>
> sqlwrite eval "CREATE TABLE $tablename($eval)"
>
> I am really struggling with that last line. I've tried all kinds of syntax
> and every one fails. It seems to me that Tcl interprets the form
> $variable(parentheses) as an element of an array. I can only make
> it work hard coding the table's name, which is not what I want.
>
> What would the correct way for that be?
>
>
> You want more code, don't you? Alright.
>
> set datatypes {
> Dirname text
> Contains int
> Data real
> X text
> Y int
> Z real
> }
>
> set fe 0
> foreach i $datatypes {
> append eval " [lindex $datatypes $fe]"
> incr fe
> append eval " [lindex $datatypes $fe]"
> if {[expr $fe + 1] < [llength $datatypes]} {
> set eval "$eval,"
> } else {set eval "$eval"}
> incr fe
> }
>
> puts $eval
>
> sqlite3 sqlwrite /path/to/file.db
> set tablename "nicetable"
> sqlwrite eval "CREATE TABLE $tablename($eval)"
>

Correct code:
set datatypes {
Dirname text
Contains int
Data real
X text
Y int
Z real
}
sqlite3 sqlwrite /path/to/file.db
set tablename "nicetable"
sqlwrite eval "CREATE TABLE $tablename ( [join $eval {,}] )"

--
+----------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald.Lester@kng-consulting.net |
+----------------------------------------------------------------------+

Re: Help with sqlite statement

<tlavn3$1dom$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10202&group=comp.lang.tcl#10202

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!a5rWVvs5S5ZXUwkNcVnRMw.user.46.165.242.75.POSTED!not-for-mail
From: saitolo...@gmail.com (saitology9)
Newsgroups: comp.lang.tcl
Subject: Re: Help with sqlite statement
Date: Sat, 19 Nov 2022 11:19:46 -0500
Organization: Aioe.org NNTP Server
Message-ID: <tlavn3$1dom$1@gioia.aioe.org>
References: <20221119095522.10f94c88@lud1.home>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="46870"; posting-host="a5rWVvs5S5ZXUwkNcVnRMw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.3.2
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: saitology9 - Sat, 19 Nov 2022 16:19 UTC

On 11/19/2022 7:55 AM, Luc wrote:
>
> sqlwrite eval "CREATE TABLE $tablename($eval)"
>
> I am really struggling with that last line. I've tried all kinds of syntax

A couple of options: You can use space around the parentheses:
"$tablename ($eval)". Or you can escape them: "$tablename\($eval\)".

Re: Help with sqlite statement

<tlb9je$39geg$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10204&group=comp.lang.tcl#10204

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: Help with sqlite statement
Date: Sat, 19 Nov 2022 19:08:30 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <tlb9je$39geg$1@dont-email.me>
References: <20221119095522.10f94c88@lud1.home>
Injection-Date: Sat, 19 Nov 2022 19:08:30 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="b8370687bab7fb3570e987497a6e3094";
logging-data="3457488"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX180xaJ2j4CP5eTppaRHorAW"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:r7o9zELKsyAXi1c2e6YkP5vBGxk=
 by: Rich - Sat, 19 Nov 2022 19:08 UTC

Luc <no@no.no> wrote:
> Hello. Very simple question. I think.
>
> foreach i $columns {
> blah blah blah,
> create list of columns and types,
> set eval [list of columns]
> }
>
> sqlwrite eval "CREATE TABLE $tablename($eval)"
>
> I am really struggling with that last line. I've tried all kinds of syntax
> and every one fails. It seems to me that Tcl interprets the form
> $variable(parentheses) as an element of an array. I can only make
> it work hard coding the table's name, which is not what I want.
>
> What would the correct way for that be?

Is there a reason you want to dynamically create SQL create table
statements?

Most often, the SQL table structure is pre-determined, and one's code
simply inserts/deletes/updates with the existing tables.

Re: Help with sqlite statement

<20221119181923.5cc738b2@lud1.home>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10205&group=comp.lang.tcl#10205

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!pgFU3G4+2WW01qgkGGaBqw.user.46.165.242.75.POSTED!not-for-mail
From: no...@no.no (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: Help with sqlite statement
Date: Sat, 19 Nov 2022 18:19:23 -0300
Organization: Aioe.org NNTP Server
Message-ID: <20221119181923.5cc738b2@lud1.home>
References: <20221119095522.10f94c88@lud1.home>
<tlb9je$39geg$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="43002"; posting-host="pgFU3G4+2WW01qgkGGaBqw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Newsreader: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu)
X-Notice: Filtered by postfilter v. 0.9.2
 by: Luc - Sat, 19 Nov 2022 21:19 UTC

On Sat, 19 Nov 2022 10:01:21 -0600, Gerald Lester wrote:

> Correct code:
> sqlwrite eval "CREATE TABLE $tablename ( [join $eval {,}] )"

That works for the insertion of data, but not for 'create table.'
For 'create table' I need two words before each comma: the name of
the field and the data type.

On Sat, 19 Nov 22 16:28:06 GMT, clt.to.davebr@dfgh.net wrote:

> More ideas:
>
> # foreach can take more than one value from the list at a time
> foreach {name type} $datatypes {
> # first make a list of column definitions
> lappend colDefs "$name $type"

Oooh, I didn't know that. That's useful. I could have used it so many
times if I'd known that before.

Many other great tips there. Thank you all!

On Sat, 19 Nov 2022 19:08:30 -0000 (UTC), Rich wrote:

> Is there a reason you want to dynamically create SQL create table
> statements?
>
> Most often, the SQL table structure is pre-determined, and one's code
> simply inserts/deletes/updates with the existing tables.

Well, it's not pre-determined until I determine it. I am creating the
table from scratch. Since I make many mistakes, I didn't use sqlite
for some 15 years and have to learn everything again, it's definitely
better to automate the creation of the database, tables and everything.
Every time I screw up, the script rebuilds the test pad and I can
pick it up where I left off.

Again, thank you all for the tips. They really help.

--
Luc
>>

Re: Help with sqlite statement

<tlbmp3$3ag4h$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10207&group=comp.lang.tcl#10207

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: Help with sqlite statement
Date: Sat, 19 Nov 2022 22:53:23 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 105
Message-ID: <tlbmp3$3ag4h$1@dont-email.me>
References: <20221119095522.10f94c88@lud1.home> <tlb9je$39geg$1@dont-email.me> <20221119181923.5cc738b2@lud1.home>
Injection-Date: Sat, 19 Nov 2022 22:53:23 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="b8370687bab7fb3570e987497a6e3094";
logging-data="3489937"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/XViCREEIE20rnUR5o3M1L"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:7PTJ8aEX2totDvSvt9vD4g7Jnv4=
 by: Rich - Sat, 19 Nov 2022 22:53 UTC

Luc <no@no.no> wrote:
> On Sat, 19 Nov 2022 10:01:21 -0600, Gerald Lester wrote:
>
>> Correct code:
>> sqlwrite eval "CREATE TABLE $tablename ( [join $eval {,}] )"
>
>
> That works for the insertion of data, but not for 'create table.'
> For 'create table' I need two words before each comma: the name of
> the field and the data type.
>
>
>
> On Sat, 19 Nov 22 16:28:06 GMT, clt.to.davebr@dfgh.net wrote:
>
>> More ideas:
>>
>> # foreach can take more than one value from the list at a time
>> foreach {name type} $datatypes {
>> # first make a list of column definitions
>> lappend colDefs "$name $type"
>
>
> Oooh, I didn't know that. That's useful. I could have used it so many
> times if I'd known that before.

It /is/ right there in the documentation:

SYNOPSIS
foreach varname list body
foreach varlist1 list1 ?varlist2 list2 ...? body

Note the second version.

And a bit further down in the manpage:

In the general case there can be more than one value list (e.g.,
list1 and list2), and each value list can be associated with a
list of loop variables (e.g., varlist1 and varlist2). During
each iteration of the loop the variables of each varlist are
assigned consecutive values from the corresponding list. Values
in each list are used in order from first to last, and each
value is used exactly once. The total number of loop iterations
is large enough to use up all the values from all the value
lists. If a value list does not contain enough elements for
each of its loop variables in each iteration, empty values are
used for the missing elements.

You can do all kinds of 'magic' with foreach.

> On Sat, 19 Nov 2022 19:08:30 -0000 (UTC), Rich wrote:
>
>> Is there a reason you want to dynamically create SQL create table
>> statements?
>>
>> Most often, the SQL table structure is pre-determined, and one's code
>> simply inserts/deletes/updates with the existing tables.
>
>
> Well, it's not pre-determined until I determine it. I am creating the
> table from scratch. Since I make many mistakes, I didn't use sqlite
> for some 15 years and have to learn everything again, it's definitely
> better to automate the creation of the database, tables and everything.
> Every time I screw up, the script rebuilds the test pad and I can
> pick it up where I left off.

By 'predetermined' I mean that in the most common instance, you know
the Sqlite DB will represent, say, an address book (this below will be
very US centric, but is meant as an example). That fact
'pre-determines' the table structure, so your code would do this to
'initialize' the database: (assuming "db" is the command already setup
to point to a file on disk):

db eval {create table addresses (first_name text, last_name text,
address1 text, address2 text,
city text, state text, zip text);}
db eval {create index zip_index on addresses(zip);} ;# assuming you
# planned to 'look up by zip code' often

No need to dynamically 'write' SQL create table statements, just write
out the full create table statement in full once up front and be done.

Then, later, you'd do things like:

db eval {select * from addresses where zip = '12345';}

to get all addresses in zipcode '12345'.

Or:

db eval {insert into addresses (first_name, last_name, address1,
city, state, zip) values (:first, :last, :addr, :city,
:state, :zip);}

To insert the contents of the tcl variables "first" "last" "addr"
"city" "state" "zip", visible in the current variable context, into a
new row in the database.

For 98% of most uses of SQL databases, there is no need to dynamically
write the create table statements (as in the code 'writes' the create
table statements as opposed to a person just 'writing it out in full up
front'). The other 2% is when one is doing something like building a
"SQL query interface app" for others to use to build databases -- and
you've not told us that is what you are trying to do yet.

Re: Help with sqlite statement

<tlca4p$1vri$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10209&group=comp.lang.tcl#10209

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!JNQqFS25rnmZhNEZ11/SOA.user.46.165.242.75.POSTED!not-for-mail
From: Gerald.L...@KnG-Consulting.net (Gerald Lester)
Newsgroups: comp.lang.tcl
Subject: Re: Help with sqlite statement
Date: Sat, 19 Nov 2022 22:23:54 -0600
Organization: KnG Consulting, LLC
Message-ID: <tlca4p$1vri$1@gioia.aioe.org>
References: <20221119095522.10f94c88@lud1.home> <tlauki$10hc$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="65394"; posting-host="JNQqFS25rnmZhNEZ11/SOA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.11.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Gerald Lester - Sun, 20 Nov 2022 04:23 UTC

On 11/19/22 10:01, Gerald Lester wrote:
> On 11/19/22 06:55, Luc wrote:
>> Hello. Very simple question. I think.
>>
>> foreach i $columns    {
>>     blah blah blah,
>>     create list of columns and types,
>>     set eval [list of columns]
>> }
>>
>> sqlwrite eval "CREATE TABLE $tablename($eval)"
>>
>> I am really struggling with that last line. I've tried all kinds of
>> syntax
>> and every one fails. It seems to me that Tcl interprets the form
>> $variable(parentheses) as an element of an array. I can only make
>> it work hard coding the table's name, which is not what I want.
>>
>> What would the correct way for that be?
>>
>>
>> You want more code, don't you? Alright.
>>
>> set datatypes {
>>     Dirname        text
>>     Contains    int
>>     Data        real
>>     X            text
>>     Y            int
>>     Z            real
>> }
>>
>> set fe 0
>> foreach i $datatypes    {
>>     append eval " [lindex $datatypes $fe]"
>>     incr fe
>>     append eval " [lindex $datatypes $fe]"
>>         if {[expr $fe + 1] < [llength $datatypes]}    {
>>             set eval "$eval,"
>>         } else {set eval "$eval"}
>>     incr fe
>> }
>>
>> puts $eval
>>
>> sqlite3 sqlwrite /path/to/file.db
>> set tablename "nicetable"
>> sqlwrite eval "CREATE TABLE $tablename($eval)"
>>
>
Correct code:
 set datatypes {
     {Dirname      text}
     {Contains    int}
     {Data        real}
     {X            text}
     {Y            int}
     {Z            real}
 }
 sqlite3 sqlwrite /path/to/file.db
 set tablename "nicetable"
 sqlwrite eval "CREATE TABLE $tablename ( [join $eval {,}] )"

--
+----------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald.Lester@kng-consulting.net |
+----------------------------------------------------------------------+

Re: Help with sqlite statement

<20221120111310.33263c35@lud1.home>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10210&group=comp.lang.tcl#10210

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!bkBHs4L8p5Ilk4vflQt/cg.user.46.165.242.75.POSTED!not-for-mail
From: no...@no.no (Luc)
Newsgroups: comp.lang.tcl
Subject: Re: Help with sqlite statement
Date: Sun, 20 Nov 2022 11:13:10 -0300
Organization: Aioe.org NNTP Server
Message-ID: <20221120111310.33263c35@lud1.home>
References: <20221119095522.10f94c88@lud1.home>
<tlauki$10hc$1@gioia.aioe.org>
<tlca4p$1vri$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: gioia.aioe.org; logging-data="64582"; posting-host="bkBHs4L8p5Ilk4vflQt/cg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
X-Newsreader: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu)
 by: Luc - Sun, 20 Nov 2022 14:13 UTC

On Sat, 19 Nov 2022 22:23:54 -0600, Gerald Lester wrote:

> Correct code:
>  set datatypes {
>      {Dirname      text}
>      {Contains    int}
>      {Data        real}
>      {X            text}
>      {Y            int}
>      {Z            real}
>  }
>  sqlite3 sqlwrite /path/to/file.db
>  set tablename "nicetable"
>  sqlwrite eval "CREATE TABLE $tablename ( [join $eval {,}] )"

Thank you again. I love syntatic sugar! And Tcl is the best for that.

Just for the sake of discussion, I noticed that the resulting $eval by
that approach preserves all the tabs I used for "drawing" a neat table
in the code. So the resulting $eval looks messy.

That doesn't matter for creating database tables, but in other
situations I would have to do something like this:

set eval [join $datatypes ","]
regsub -all {\s+} $eval { } eval
regsub -all {,} $eval {, } eval

Unless you have some other less obvious trick up your sleeve. :-)

--
Luc
>>

Re: Help with sqlite statement

<tledec$lgh$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10214&group=comp.lang.tcl#10214

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!JNQqFS25rnmZhNEZ11/SOA.user.46.165.242.75.POSTED!not-for-mail
From: Gerald.L...@KnG-Consulting.net (Gerald Lester)
Newsgroups: comp.lang.tcl
Subject: Re: Help with sqlite statement
Date: Sun, 20 Nov 2022 17:32:28 -0600
Organization: KnG Consulting, LLC
Message-ID: <tledec$lgh$1@gioia.aioe.org>
References: <20221119095522.10f94c88@lud1.home> <tlauki$10hc$1@gioia.aioe.org>
<tlca4p$1vri$1@gioia.aioe.org> <20221120111310.33263c35@lud1.home>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="22033"; posting-host="JNQqFS25rnmZhNEZ11/SOA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.11.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Gerald Lester - Sun, 20 Nov 2022 23:32 UTC

On 11/20/22 08:13, Luc wrote:
> On Sat, 19 Nov 2022 22:23:54 -0600, Gerald Lester wrote:
>
>> Correct code:
>>  set datatypes {
>>      {Dirname      text}
>>      {Contains    int}
>>      {Data        real}
>>      {X            text}
>>      {Y            int}
>>      {Z            real}
>>  }
>>  sqlite3 sqlwrite /path/to/file.db
>>  set tablename "nicetable"
>>  sqlwrite eval "CREATE TABLE $tablename ( [join $eval {,}] )"
>
>
> Thank you again. I love syntatic sugar! And Tcl is the best for that.
>
> Just for the sake of discussion, I noticed that the resulting $eval by
> that approach preserves all the tabs I used for "drawing" a neat table
> in the code. So the resulting $eval looks messy.
>
> That doesn't matter for creating database tables, but in other
> situations I would have to do something like this:
>
> set eval [join $datatypes ","]
> regsub -all {\s+} $eval { } eval
> regsub -all {,} $eval {, } eval
>
> Unless you have some other less obvious trick up your sleeve. :-)
>

I would never use regsub for that -- way overkill. String map is where
I'd go, but why bother?

--
+----------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald.Lester@kng-consulting.net |
+----------------------------------------------------------------------+

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor