Hi!
2009.04.23. 9:23 keltezéssel, John R Pierce írta:
durumdara wrote:
Hi!
In a mod_py application I wanna write a wrapper that handle all PSQL
data view with paging/slicing.
..
Inserts all records to a temp table.
Check the affected rows (as count).
Slicing the records.
Fetch the slice records.
Destroy temp table.
how about KEEPING the data in this slice format, and keeping the count
somewhere ? you'd need to update the count and slice info when new
data gets added, but perhaps thats better than doing it every time you
want to view a slice?
This is a complicated thing.
These datas are provided by a query, with some user's conditions.
For example:
Text = Free String Search
Live = This data is living
Category = Some category
SubCategory = Some subcategory
...
etc.
So your way is possible working with this pseudo code:
def Slicing(PageIndex, Conditions):
# Del recs that have older than 30 minutes
delsql = "delete from pagingtable where inserted < %s" %
IncWithMinutes(Now, -30)
ExecSQL(delsql)
# The Query
datasql = BuildSQL(Conditions)
# Have same query in the pool?
checksql = "select count from pagingtable where sql='%s'" %
SafeEscape(datasql)
records = ExecSQL(checksql)
if records:
# Yes
count = records[0]['COUNT']
else:
# No, we must run a count sql to check
countsql = BuildSQL(Conditions, Count = 1)
datarecords = ExecSQL(countsql)
datarecord = datarecords[0]
count = datarecord['COUNT']
# We must insert it to the paging table
InsertPagingRecord(datasql, count)
...
# Use the count
...
finalsql = BuildSQL(Conditions, WithPaging = PageIndex)
finalrecords = ExecSQL(finalsql)
...
But possible it is too complex and I fear that it cause more pain than I
winning in it... (deadlocks?)...
Thanks for your help:
dd
--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general