Finding out how many rows is selected in database
How do I do subject ? I need to do one thing if any rows is returned and another if there is no records in the database -- ************************ Gitte Wange Jensen System Squid Developer MMManager Aps +45 29 72 79 72 gitte@mmmanager.org ************************
<dtml-in queryname> Houston we have records <dtml-else> No records found> </dtml-in> ----- Original Message ----- From: "Gitte Wange" <gitte@mmmanager.org> To: <zope@zope.org> Sent: Thursday, April 05, 2001 2:42 PM Subject: [Zope] Finding out how many rows is selected in database
How do I do subject ?
I need to do one thing if any rows is returned and another if there is no records in the database
-- ************************ Gitte Wange Jensen
System Squid Developer MMManager Aps +45 29 72 79 72
gitte@mmmanager.org ************************
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
On 05 Apr 2001 14:51:12 +0100, Phil Harris wrote:
<dtml-in queryname> Houston we have records <dtml-else> No records found> </dtml-in>
Okay I forgot one thing - I also need to find out how many rows are returned.
----- Original Message ----- From: "Gitte Wange" <gitte@mmmanager.org> To: <zope@zope.org> Sent: Thursday, April 05, 2001 2:42 PM Subject: [Zope] Finding out how many rows is selected in database
How do I do subject ?
I need to do one thing if any rows is returned and another if there is no records in the database
-- ************************ Gitte Wange Jensen
System Squid Developer MMManager Aps +45 29 72 79 72
gitte@mmmanager.org ************************
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
untested in this form: <dtml-call "REQUEST.set('recs',queryname())"> <dtml-var "_.len(recs)"> <dtml-in recs> </dtml-in> ----- Original Message ----- From: "Gitte Wange" <gitte@mmmanager.org> To: "Phil Harris" <phil.harris@zope.co.uk> Cc: <zope@zope.org> Sent: Thursday, April 05, 2001 3:12 PM Subject: Re: [Zope] Finding out how many rows is selected in database
On 05 Apr 2001 14:51:12 +0100, Phil Harris wrote:
<dtml-in queryname> Houston we have records <dtml-else> No records found> </dtml-in>
Okay I forgot one thing - I also need to find out how many rows are returned.
----- Original Message ----- From: "Gitte Wange" <gitte@mmmanager.org> To: <zope@zope.org> Sent: Thursday, April 05, 2001 2:42 PM Subject: [Zope] Finding out how many rows is selected in database
How do I do subject ?
I need to do one thing if any rows is returned and another if there is no records in the database
-- ************************ Gitte Wange Jensen
System Squid Developer MMManager Aps +45 29 72 79 72
gitte@mmmanager.org ************************
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
On 05 Apr 2001 14:54:55 +0100, Chris Withers wrote:
Gitte Wange wrote:
How do I do subject ?
How about finding a mailing list about SQL?
Well finding out how many rows are returned isn't - AFAIK - a SQL thing; it's a Zope thing. In PHP I did it by saying mysql_numrows (which is a php function) so I guessed that perhaps Zope had a function like that. Gitte
cheers,
Chris
(There are _plenty_ of books on that too ;-)
Use some variation on this: Assume the query method is called "query1" <!-- Execute the query --> <dtml-let results=query1> <!-- display the number of rows --> There are <dtml-var "_.len(results)"> rows in the results. </dtml-let> In your case, you would probably want to assign the number of rows to a variable - maybe with dtml-let - and use it in a dtml-if element. Cheers, Tom P Gitte Wange Subject: [Zope] Finding out how many rows is selected in database
How do I do subject ?
I need to do one thing if any rows is returned and another if there is no records in the database
I need to do one thing if any rows is returned and another if there is no records in the database
http://zope.nipltd.com/public/lists/zope-archive.nsf/ByKey/BEBF9A98F9A59B3F
On 05 Apr 2001 09:57:14 -0500, Steve Drees wrote:
I need to do one thing if any rows is returned and another if there is no records in the database
http://zope.nipltd.com/public/lists/zope-archive.nsf/ByKey/BEBF9A98F9A59B3F
Thanx but it only helped a bit ... See he has the same problem as me - if need to do one thing if there are records returned and another if no records are returned. Actually I need to add a new item to my database with one number higher than the item with the highest number, e.g. if there are an item in the database with number 2 then the new one must have number 3. And if there are no items then the new one must have number 1. ANy good ideas ? The ones I got earlyer doesn't work Gitt
Gitte Wange wrote:
On 05 Apr 2001 09:57:14 -0500, Steve Drees wrote:
I need to do one thing if any rows is returned and another if there is no records in the database
http://zope.nipltd.com/public/lists/zope-archive.nsf/ByKey/BEBF9A98F9A59B3F
Thanx but it only helped a bit ... See he has the same problem as me - if need to do one thing if there are records returned and another if no records are returned.
Actually I need to add a new item to my database with one number higher than the item with the highest number, e.g. if there are an item in the database with number 2 then the new one must have number 3. And if there are no items then the new one must have number 1.
ANy good ideas ? The ones I got earlyer doesn't work
Gitt
That is probably best accomplished within the SQL code. Most databases provide facilities for this to prevent race conditions. For example, if you are using a sequence in postgreSQL, you can call functions like nextval() and currval() within your SQL to accomplish this. You could also use the max() SQL function to return the maximum field value and add one to it and insert it in the new record. In fact, most databases have a sequence or serial type that does this entirely automatically for you. Take a peek at you database documentation. -- | Casey Duncan | Kaivo, Inc. | cduncan@kaivo.com `------------------>
You need to get a book on SQL. Gitte Wange wrote -
Actually I need to add a new item to my database with one number higher than the item with the highest number, e.g. if there are an item in the database with number 2 then the new one must have number 3. And if there are no items then the new one must have number 1.
Say the table is "person", and the field that has the number is "id". Then select max(id) from person gives you the largest one. Or you could have the database calculate the next value for you: select 1+max(id) as next_id from person This will return a single row that has a single cell named "next_id". You should not just count the rows, since if you delete a row, the row count will not match the max id number. Tom P
Citat "Thomas B. Passin" <tpassin@mitretek.org>:
You need to get a book on SQL.
Gitte Wange wrote -
Actually I need to add a new item to my database with one number higher than the item with the highest number, e.g. if there are an item in the database with number 2 then the new one must have number 3. And if there are no items then the new one must have number 1.
Say the table is "person", and the field that has the number is "id". Then
select max(id) from person
gives you the largest one. Or you could have the database calculate the next value for you:
select 1+max(id) as next_id from person
This will return a single row that has a single cell named "next_id".
You should not just count the rows, since if you delete a row, the row count will not match the max id number.
Tom P
Damn ME ! I know that - just didn't think of it that way. Sorry! Well if you make MySQL select the next_id for you - what happens then if there are no records in the table? Will it then return 1 (if you say select max(id)+1) ??? Gitte
Gitte Wange wrote - Well if you make MySQL select the next_id for you - what happens then if there are no records in the table? Will it then return 1 (if you say select max(id)+1) ??? It ***should*** return null (that is, 1+null-->null). SQLAnywhere does (I just tested it for you). But I don't know if MySQL acts correctly or not. I don't have it installed. Just make a table with one column, don't populate it, and try it out. Cheers, Tom P
On 05 Apr 2001 15:05:57 -0400, Thomas B. Passin wrote:
Gitte Wange wrote -
Well if you make MySQL select the next_id for you - what happens then if there are no records in the table? Will it then return 1 (if you say select max(id)+1) ???
It ***should*** return null (that is, 1+null-->null). SQLAnywhere does (I just tested it for you). But I don't know if MySQL acts correctly or not. I don't have it installed. Just make a table with one column, don't populate it, and try it out.
Cheers,
Tom P
FYI - MySQL also returns null So I presume that you can make a test like this: <dtml-if FindAnyRecords> <dtml-call expr="InsertRecordWithNext_id(next_id=next_id)"> <dtml-else> <dtml-call expr="InsertRecordWithNext_id(next_id=1)"> </dtml-if> I have sensed that some people on this list is a bit "anoyed" (perhaps a wrong word) about my postings - I am sorry to say this but the Zope documentation isn't the best :-) Regards, Gitte
Gitte said...
I have sensed that some people on this list is a bit "anoyed" (perhaps a wrong word) about my postings - I am sorry to say this but the Zope documentation isn't the best :-)
Regards, Gitte
Gitte, As they say, there's no such thing as a dumb question (although there are some that come close :). I've been watching your questions and the replies you've received and have learned a few things from the discussions. Please keep asking! As for the documentation, it's getting better all the time (Zope book, Dieter's book, NIP's archives, etc...)! Thanks, Eric.
On Thu, 5 Apr 2001, Eric Walstad wrote:
Gitte said...
I have sensed that some people on this list is a bit "anoyed" (perhaps a wrong word) about my postings - I am sorry to say this but the Zope documentation isn't the best :-)
Regards, Gitte
Gitte, As they say, there's no such thing as a dumb question (although there are some that come close :). I've been watching your questions and the replies you've received and have learned a few things from the discussions. Please keep asking! As for the documentation, it's getting better all the time (Zope book, Dieter's book, NIP's archives, etc...)! Thanks, Eric.
Yep, the documentation is scattered, and sometimes hard to follow. Unfortunately, though, sometimes people respond to questions with answers that suggest that everyone reads every message to the list, and has for several months. Some questions are hard to search for answers to, because the question is conceptual, and evades easy keyword searches. Of course, sometimes people post questions that they could have answered easily, from straightforward references, or by doing a six-second google search. (sigh. Once in a while, I've posted a question, and then realized I hadn't done my due diligence in looking for the answer first.) As always, good advice is: . make your posting titles obvious and clear (change the titles to something better, if need be, when responding) . add keywords to your post, if it will help future searchers find things. . consider contributing your knowledge to the ZDP faq (zdp.zope.org). [BTW, are there *no* links to ZDP on the Zope web site? Why not?] . consider writing a HOWTO from what you learn. . be mindful that we're from different cultures. I've rec'd some email from people that I assumed where quite curt or rude, and then realized that I misread their language cues or that they were just in a hurry to answer my question so that they could help other. So, Gitte, please don't take offense. Have a thick skin. Keep asking. And, of course, as everyone says, RTFM. :-) -- Joel Burton <jburton@scw.org> Director of Information Systems, Support Center of Washington
participants (8)
-
Casey Duncan -
Chris Withers -
Eric Walstad -
Gitte Wange -
Joel Burton -
Phil Harris -
Steve Drees -
Thomas B. Passin