473,799 Members | 3,006 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

database persistence with mysql, sqlite

Hi,

I want to run a database query and then display the first 10 records
on a web page. Then I want to be able to click the 'Next' link on the
page to show the next 10 records, and so on.

My question is how to implement paging, i.e. the 'Next/Prev' NN
records without reestablishing a database connection every time I
click Next/Prev? Is it at all possible with cgi/mod_python?

For example, in a NON-web environment, with sqlite3 and most other
modules, I can establish a database connection once, get a cursor
object on which I run a single 'SELECT * FROM TABLE' statement and
then use cursor.fetchman y(NN) as many times as there are still results
left from the initial query.

How do I do the same for the web? I am not using any high-level
framework. I am looking for a solution at the level of cgi or
mod_python (Python Server Pages under Apache). To call
cursor.fetchman y(NN) over and over I need to pass a handle to the
database connection but how do I keep a reference to the cursor object
across pages? I use mysql and sqlite3 as databases, and I am looking
for an approach that would work with both database types (one at a
time). So far I have successfully used the following modules for
database access: sqlite3, mysqld, and pyodbc.

So far, with mysql I use 'SELECT * FROM TABLE LIMIT L1, L2' where L1
and L2 define the range for the 'Next' and 'Previous' commands. I
have to run the query every time a click a 'Next/Prev' link. But I am
not sure that this is the best and most efficient way. I suppose using
CURSOR.FETCHMAN Y(NN) would probably be faster and nicer but how do I
pass an object reference across pages? Is it possible without any
higher-level libraries?

What would be the proper way to do it on a non-enterprise scale?

Would SqlAlchemy or SqlObject make things easier with regard to
database persistence?

Sep 22 '07 #1
4 3036
In message <11************ **********@22g2 000hsm.googlegr oups.com>, coldpizza
wrote:
So far, with mysql I use 'SELECT * FROM TABLE LIMIT L1, L2' where L1
and L2 define the range for the 'Next' and 'Previous' commands. I
have to run the query every time a click a 'Next/Prev' link. But I am
not sure that this is the best and most efficient way.
Try it first, then see what happens. Remember, premature optimization is the
root of all (programming) evil.
Sep 24 '07 #2
coldpizza wrote:
>Hi,

I want to run a database query and then display the first 10 records
on a web page. Then I want to be able to click the 'Next' link on the
page to show the next 10 records, and so on.

My question is how to implement paging, i.e. the 'Next/Prev' NN
records without reestablishing a database connection every time I
click Next/Prev? Is it at all possible with cgi/mod_python?

For example, in a NON-web environment, with sqlite3 and most other
modules, I can establish a database connection once, get a cursor
object on which I run a single 'SELECT * FROM TABLE' statement and
then use cursor.fetchman y(NN) as many times as there are still results
left from the initial query.

How do I do the same for the web? I am not using any high-level
framework. I am looking for a solution at the level of cgi or
mod_python (Python Server Pages under Apache). To call
cursor.fetchma ny(NN) over and over I need to pass a handle to the
database connection but how do I keep a reference to the cursor object
across pages? I use mysql and sqlite3 as databases, and I am looking
for an approach that would work with both database types (one at a
time). So far I have successfully used the following modules for
database access: sqlite3, mysqld, and pyodbc.

Apache/cgi just dont work this way. When apache receives a new request
(a cgi being called), it starts a new thread, it execute him, and gives
the client some result. AND THEN KILL THE THREAD. Altough i never used
it, what i think you need is fast cgi (fcgi), wich takes care of
persistent connections to a web server.

Cheers.
Gerardo
Sep 24 '07 #3
On Sep 24, 7:23 am, Lawrence D'Oliveiro <l...@geek-
central.gen.new _zealandwrote:
In message <1190502677.970 811.181...@22g2 000hsm.googlegr oups.com>, coldpizza
wrote:
So far, with mysql I use 'SELECT * FROM TABLE LIMIT L1, L2' where L1
and L2 define the range for the 'Next' and 'Previous' commands. I
have to run the query every time a click a 'Next/Prev' link. But I am
not sure that this is the best and most efficient way.
Try it first, then see what happens. Remember, premature optimization is the
root of all (programming) evil.
It turned out that the method above ('SELECT * FROM TABLE LIMIT L1,
L2') works ok both with mysql and sqlite3, therefore I have decided to
stick with it until I find something better. With Sqlite3 you are
supposed to use LIMIT 10 OFFSET NN, but it also apparently supports
the mysql syntax (LIMIT NN, 10) for compatibility reasons.

Sep 24 '07 #4
On 2007-09-23 01:11, coldpizza wrote:
Hi,

I want to run a database query and then display the first 10 records
on a web page. Then I want to be able to click the 'Next' link on the
page to show the next 10 records, and so on.

My question is how to implement paging, i.e. the 'Next/Prev' NN
records without reestablishing a database connection every time I
click Next/Prev? Is it at all possible with cgi/mod_python?

For example, in a NON-web environment, with sqlite3 and most other
modules, I can establish a database connection once, get a cursor
object on which I run a single 'SELECT * FROM TABLE' statement and
then use cursor.fetchman y(NN) as many times as there are still results
left from the initial query.

How do I do the same for the web? I am not using any high-level
framework. I am looking for a solution at the level of cgi or
mod_python (Python Server Pages under Apache). To call
cursor.fetchman y(NN) over and over I need to pass a handle to the
database connection but how do I keep a reference to the cursor object
across pages? I use mysql and sqlite3 as databases, and I am looking
for an approach that would work with both database types (one at a
time). So far I have successfully used the following modules for
database access: sqlite3, mysqld, and pyodbc.

So far, with mysql I use 'SELECT * FROM TABLE LIMIT L1, L2' where L1
and L2 define the range for the 'Next' and 'Previous' commands. I
have to run the query every time a click a 'Next/Prev' link. But I am
not sure that this is the best and most efficient way. I suppose using
CURSOR.FETCHMAN Y(NN) would probably be faster and nicer but how do I
pass an object reference across pages? Is it possible without any
higher-level libraries?

What would be the proper way to do it on a non-enterprise scale?
Depends on what "enterprise " scale means to you :-)

The easiest way to get excellent performance for such queries is
using a long running process, mod_scgi and have the browser
send a session cookie for you to use to identify the request.
You can then open the connection and keep it open while the user
browses the site.

If you want to save yourself from most of the details,
just use Zope or Plone + e.g. our mxODBC Zope DA for the
database connection (it works with all the databases
you mention on Windows, Linux and Mac OS X).

Even if you don't want to code things using Zope/Plone,
you should still consider it for taking care of all the
middleware logic and then write your application as
separate package which you hook into Zope/Plone using
"external methods" or "Python scripts" (in their Zope
sense).
Would SqlAlchemy or SqlObject make things easier with regard to
database persistence?
Not really: they don't provide the session mechanisms you
would need.

--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source (#1, Sep 25 2007)
>>Python/Zope Consulting and Support ... http://www.egenix.com/
mxODBC.Zope.D atabase.Adapter ... http://zope.egenix.com/
mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
_______________ _______________ _______________ _______________ ____________

:::: Try mxODBC.Zope.DA for Windows,Linux,S olaris,MacOSX for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
Sep 25 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
1819
by: chris | last post by:
how would i duplicate a database content into another database i have ssh access and want to do this without downloading the database and uploading it again thanks
6
1579
by: ionel | last post by:
I'm looking for a thread-safe database. Preferably an embedded, sql database. What are the best choices in terms of speed ? -- ionel.
33
3286
by: Alexander Muylaert | last post by:
Hi I'm looking for a small and light file structure for my app. I need to store a bunch of small streams. It is always like key - data. I need to be able to get, add, delete and update these streams. I also should be able to iterate through the entire table. No complex sql queries, etc... Anybody knows an alternative. It doesn't have to be free, but if would be
6
3632
by: nc | last post by:
Anyone able to help me out and tell me if there is a default datafile type installed with PHP? If there is no default datafile type, what would be the most common type of datafile and does the server type matter (ie, IIS / apache) matter in this instance? Thanks alot for any help. Ralph
3
1205
by: ljh | last post by:
If I am using VB.Net 2005 with SQL Express or Developer edition and want to embed the db into my project, how do I do that? I can't find anything on embedding the db into a VB.Net 2005 app anywhere.....
19
2827
by: jupiter | last post by:
Hi guys!!! Just one quick question... Which database module should I use when I want to use multi threading as my application requires lots of data from internet ???? I also want this database module to be fast, simple n efficient, in any case multi threading capabilities are # 1 requirement.
2
3346
by: webcm123 | last post by:
People say that structural programming isn't good for database connection. I code fast-running structural oriented CMS and I don't know what I should do. I use mysql connection using mysql_*. I want also to use SQLite. Can you give me some advices? 1. PHP4 is still used. I want to be compatible. 2. There are various methods - MySQL, MySQLi, SQLite, PDO... I have
24
2104
by: sonos | last post by:
Hi, I am working on a program to archive data to disk. At what point is it best to use a relational database like MySQL as the backend instead of a C program alone? Thanks to any and all replies.
17
2782
by: darien.watkins | last post by:
Kindof a poll, kindof curiosity... What is your favorite python - database combination? I'm looking to make an app that has a local DB and a server side DB. I'm looking at python and sqlite local side and sql server side. Any suggestions???? Darien
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10247
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7571
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.