Re: How do I browse a database ?

From: R.Wieser <address_at_not.available>
Date: Mon, 12 Aug 2019 10:08:13 +0200
Message-ID: <qir6pm$2un$1_at_gioia.aioe.org>


Jerry,

> You'll have to look at the table itself. No table *requires* a primary > key, but it's always a good idea to have one.

[Quoted] Agreed. But /not/ having one makes it impossible to add it to the end of a selection clause. :-( I've still got to figure out how to handle such tables.

>> Than again, I just ran into this:

...
> Sorry I can't help you here.

[Quoted] After some experimenting it turned out to be embarrassing simple, namely this: "LOWER(id)". It causes the values in "id" to be converted to strings (supposedly causing the "id" results from the table to be converted into strings before sorting too), giving weird end results. I could imagine MySQL having the same problem (nudge, nudge .. does it ?)

> You may be thinking of the ORDER BY clause, which can use comma separated > column names.

[Quoted] Initially, yes. But I verified (or at least tried to verify) the WHERE usage on that webpage I posted the link to.

> And there is no default sort order in SQL. If you don't specify ORDER BY > the sort order is undetermined.

[Quoted] I ment the in-order checking of the comma-seperated equations of the WHERE clause, stopping on a non-equal comparision result. A form of an implicite AND with a "sudden death" checking termination.

You ofcourse realise that as you say that that doesn't work that way that I will, after I got the basic browsing to work, try it out. :-)

> That is the definition of an expression, not sort criteria.

[Quoted] An expression as mentioned in the WHERE branch of the below image:

https://www.sqlite.org/syntaxdiagrams.html#select-stmt

Below it are a "used by" and "references" list of links, from which I selected the "expr" one (duh :-) ). And thats the one I posted. Your honor, is that an adequate chain of evidence ? :-) (please do tell if I'm wrong there though)

Regards,
Rudy Wieser

"Jerry Stuckle" <jstucklex_at_attglobal.net> wrote in message news:qipsvu$o0s$1_at_jstuckle.eternal-september.org...

> On 8/11/2019 3:04 PM, R.Wieser wrote:

>> Jerry,
>>
>>> You don't use a temporary database. Just use the existing database. I
>>> hope you have a primary key on the table.
>>
>> :-) Thats part of the problem: my program is ment to be a generic
>> viewer,
>> which should be able to handle /any/ sqlite database. And currently
>> I'm
>> not even sure if a sqlite database must actually have a primary key.
>>
>
> You'll have to look at the table itself.  No table *requires* a primary 
> key, but it's always a good idea to have one.
>
> But I also wouldn't worry too much about using a lot of resources - SQLite 
> is good for quick data but not very good at handling large databases. 
> Other databases are much more capable.
>
>

>>> You simply add the primary key as the last sort parameter and search for
>>> the next row based on the previous one.
>>
>> Yep, that should work.
>>
>> Than again, I just ran into this:
>>
>> SELECT * FROM foo ORDER BY LOWER(id) LIMIT 7;
>>
>> "id" is the primary key column, an 8 byte integer.
>>
>> Resulting "id"s: 1, 10, 100, 1000, 100000, 10001, 10002
>>
>> I'm rather sure that all the other key values between 1 and 100002 are in
>> the table too.
>>
>> And when doing this:
>>
>> SELECT * FROM foo WHERE id<='100032' ORDER BY LOWER(id) DESC LIMIT 7;
>> (with or without the quotes around 100032)
>>
>> it thinks that the first number is 99999 (not even 100032 itself!) ...
>>
>> Yep, a string comparision where there should be an integer one. :-(
>>
>> At this moment I really could use a sqlite specific newgroup ...
>>
>
> Sorry I can't help you here.  As I said - it's been a LONG time since I've 
> used SQLite.  Well over a decade at the least.
>

>>
>>> Now the next SELECT gets a little more complicated, but:
>>
>>> WHERE (col1>val1) OR (col1= val1 AND col2>VAL2) OR
>>
>> Whut ? I thought the WHERE comparisions could be seperated by commas,
>> and
>> that the DB software would be smart enough to do the sorting that way by
>> default.
>>
>
> So, if the WHERE clause has multiple conditions they must always use 
> boolean operators between the conditions.  You may be thinking of the 
> ORDER BY clause, which can use comma separated column names.
>
> And there is no default sort order in SQL.  If you don't specify ORDER BY 
> the sort order is undetermined.
>

>> Looking .... Yup, it looks that I'm right about the expression:
>> https://www.sqlite.org/syntaxdiagrams.html#expr , seventh branch,
>> starting
>> with "(".
>>
>
> That is the definition of an expression, not sort criteria.
>

>> The only thing I have to find out is if the DB software is "smart"
>> enough.
>>
>>
>> ... but first the non-numeric sorting of a numeric column.
>>
>> Regards,
>> Rudy Wieser
>>
>>
>
>
>
> -- 
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> jstucklex_at_attglobal.net
> ================== 
Received on Mon Aug 12 2019 - 10:08:13 CEST

Original text of this message