I have the following code:
set getFirstAndLast {
SELECT MIN(WeekNo) AS FirstWeek
, MAX(WeekNo) AS LastWeek
FROM (
SELECT strftime('%W', dayDate, '+1 day') AS WeekNo
, COUNT(dayViews) AS Days
FROM dayViews
GROUP BY WeekNo
)
WHERE Days = 7
}
set selectWeek {
SELECT strftime('%W', dayDate, '+1 day') AS WeekNo
, COUNT(*) AS Days
, SUM(dayViews) AS WeekTotals
FROM dayViews
WHERE WeekNo >= :startWeek
AND WeekNo <= :endWeek
GROUP BY WeekNo
ORDER BY WeekNo
}
sqlite3 db ~/Databases/youtube.sqlite
db eval ${getFirstAndLast} {
set startWeek ${FirstWeek}
set endWeek ${LastWeek}
# set nrOfWeeks [expr { 1 + $endWeek - $startWeek }]
# puts ${nrOfWeeks}i
puts "Start with week ${FirstWeek} and en with week ${LastWeek}"
}
db eval ${selectWeek} {
if { ${Days} != 7 } {
puts "ERROR: week ${WeekNo} has ${Days} days"
}
puts [format "Week %2s has %4s views" ${WeekNo} ${WeekTotals}]
lappend viewsArr ${WeekTotals}
lappend weekArr ${WeekNo}
}
db close
puts "Got here"
When I run this I get:
Start with week 38 and en with week 45
Week 38 has 160 views
Week 39 has 92 views
Week 40 has 134 views
Week 41 has 200 views
Week 42 has 241 views
Week 43 has 241 views
Week 44 has 664 views
Week 45 has 416 views
Got here
When I uncomment the two statements in the first 'db eval' I get:
8i
Start with week 38 and en with week 45
Got here
So the set works and does not corrupt startWeek, or endWeek, bor does
it terminate the program.
But it ruins the second 'db eval'.
What could be happening here?
Even when I set nrOfWeeks2 instead of nrOfWeeks, I have the same
problem.
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
Cecil Westerhof schrieb am Sonntag, 12. November 2023 um 13:28:09 UTC+1:
I have the following code:
set getFirstAndLast {
SELECT MIN(WeekNo) AS FirstWeek
, MAX(WeekNo) AS LastWeek
FROM (
SELECT strftime('%W', dayDate, '+1 day') AS WeekNo
, COUNT(dayViews) AS Days
FROM dayViews
GROUP BY WeekNo
)
WHERE Days = 7
}
set selectWeek {
SELECT strftime('%W', dayDate, '+1 day') AS WeekNo
, COUNT(*) AS Days
, SUM(dayViews) AS WeekTotals
FROM dayViews
WHERE WeekNo >= :startWeek
AND WeekNo <= :endWeek
GROUP BY WeekNo
ORDER BY WeekNo
}
sqlite3 db ~/Databases/youtube.sqlite
db eval ${getFirstAndLast} {
set startWeek ${FirstWeek}
set endWeek ${LastWeek}
# set nrOfWeeks [expr { 1 + $endWeek - $startWeek }]
# puts ${nrOfWeeks}i
puts "Start with week ${FirstWeek} and en with week ${LastWeek}"
}
db eval ${selectWeek} {
if { ${Days} != 7 } {
puts "ERROR: week ${WeekNo} has ${Days} days"
}
puts [format "Week %2s has %4s views" ${WeekNo} ${WeekTotals}]
lappend viewsArr ${WeekTotals}
lappend weekArr ${WeekNo}
}
db close
puts "Got here"
When I run this I get:
Start with week 38 and en with week 45
Week 38 has 160 views
Week 39 has 92 views
Week 40 has 134 views
Week 41 has 200 views
Week 42 has 241 views
Week 43 has 241 views
Week 44 has 664 views
Week 45 has 416 views
Got here
When I uncomment the two statements in the first 'db eval' I get:
8i
Start with week 38 and en with week 45
Got here
So the set works and does not corrupt startWeek, or endWeek, bor does
it terminate the program.
But it ruins the second 'db eval'.
What could be happening here?
Even when I set nrOfWeeks2 instead of nrOfWeeks, I have the same
problem.
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
expr change in {} the variable type, not in ()
in the second select:
from
https://www.sqlite.org/lang_datefunc.html
Their strftime() equivalents return a string that is the text
representation of the corresponding number.
...
WHERE WeekNo >= ':startWeek'
AND WeekNo <= ':endWeek'
or
in the first 'db eval'.
puts "[tcl::unsupported::representation $endWeek]"
#int
set nrOfWeeks [expr { 1 + $endWeek - $startWeek }]
#string
#set nrOfWeeks [expr ( 1 + $endWeek - $startWeek )]
puts "[tcl::unsupported::representation $endWeek]"
# puts ${nrOfWeeks}i
greg writes:
Cecil Westerhof schrieb am Sonntag, 12. November 2023 um 13:28:09 UTC+1:
I have the following code:
set getFirstAndLast {
SELECT MIN(WeekNo) AS FirstWeek
, MAX(WeekNo) AS LastWeek
FROM (
SELECT strftime('%W', dayDate, '+1 day') AS WeekNo
, COUNT(dayViews) AS Days
FROM dayViews
GROUP BY WeekNo
)
WHERE Days = 7
}
set selectWeek {
SELECT strftime('%W', dayDate, '+1 day') AS WeekNo
, COUNT(*) AS Days
, SUM(dayViews) AS WeekTotals
FROM dayViews
WHERE WeekNo >= :startWeek
AND WeekNo <= :endWeek
GROUP BY WeekNo
ORDER BY WeekNo
}
sqlite3 db ~/Databases/youtube.sqlite
db eval ${getFirstAndLast} {
set startWeek ${FirstWeek}
set endWeek ${LastWeek}
# set nrOfWeeks [expr { 1 + $endWeek - $startWeek }]
# puts ${nrOfWeeks}i
puts "Start with week ${FirstWeek} and en with week ${LastWeek}"
}
db eval ${selectWeek} {
if { ${Days} != 7 } {
puts "ERROR: week ${WeekNo} has ${Days} days"
}
puts [format "Week %2s has %4s views" ${WeekNo} ${WeekTotals}]
lappend viewsArr ${WeekTotals}
lappend weekArr ${WeekNo}
}
db close
puts "Got here"
When I run this I get:
Start with week 38 and en with week 45
Week 38 has 160 views
Week 39 has 92 views
Week 40 has 134 views
Week 41 has 200 views
Week 42 has 241 views
Week 43 has 241 views
Week 44 has 664 views
Week 45 has 416 views
Got here
When I uncomment the two statements in the first 'db eval' I get:
8i
Start with week 38 and en with week 45
Got here
So the set works and does not corrupt startWeek, or endWeek, bor does
it terminate the program.
But it ruins the second 'db eval'.
What could be happening here?
Even when I set nrOfWeeks2 instead of nrOfWeeks, I have the same
problem.
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
expr change in {} the variable type, not in ()
in the second select:
from
https://www.sqlite.org/lang_datefunc.html
Their strftime() equivalents return a string that is the text representation of the corresponding number.
...
WHERE WeekNo >= ':startWeek'
AND WeekNo <= ':endWeek'
or
in the first 'db eval'.
puts "[tcl::unsupported::representation $endWeek]"
#int
set nrOfWeeks [expr { 1 + $endWeek - $startWeek }]
#stringIt works, but I find it strange for two reasons:
#set nrOfWeeks [expr ( 1 + $endWeek - $startWeek )]
puts "[tcl::unsupported::representation $endWeek]"
# puts ${nrOfWeeks}i
- I was always told that what is given to expr should be between '{'
and '}'.
- I would not expect that expr would change the input parameters.
I did not test it, but are you telling SQL to compare strings here? That might introduce a data-dependent bug like '2' >= '10'....
WHERE WeekNo >= ':startWeek'
AND WeekNo <= ':endWeek'
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 497 |
Nodes: | 16 (2 / 14) |
Uptime: | 25:05:37 |
Calls: | 9,793 |
Calls today: | 12 |
Files: | 13,749 |
Messages: | 6,188,097 |