473,386 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

I: caching the sql queries

I MEAN YOU CAN ACCESS ADO TROUGHT COM
AS EXPLAINED HERE:

import win32com.client
import locale
from os import sys
adCmdStoredProc = 4 # Evaluates CommandText as a stored procedure
name.
adCmdTable = 2 # Evaluates CommandText as a table name.
adInteger = 3 # A 4-byte signed integer.
adParamInput = 0x1 # from enum ParameterDirectionEnum
class DBConnect:
def __init__(self):
self.Cnn = win32com.client.Dispatch(r'ADODB.Connection')
self.ConnStr = r'File Name=C:\Graal.dsn'
self.Cnn.Open (self.ConnStr)
locale.setlocale(locale.LC_ALL , "it")

def GetHeaders(self):
dati=[]
Cmd =win32com.client.Dispatch(r'ADODB.Command')
Cmd.ActiveConnection = self.Cnn
Cmd.CommandText = 'Intestazioni'
Cmd.CommandType = adCmdTable
Cmd.CommandTimeout = 15
Rst = win32com.client.Dispatch(r'ADODB.Recordset')
Rst.Open (Cmd)

dati.append(Rst.Fields.Item('DataRiferimento').Val ue.Format("%d.%m.%Y"))
Rst.Close()
self.Cnn.Close()
return dati

def GetReturn(self, Ndg=1036):
dati=[]
if not str(Ndg).isdigit():
raise NoDataError('Il codice cliente inserito non e numerico')
Cmd =win32com.client.Dispatch(r'ADODB.Command')
Cmd.ActiveConnection = self.Cnn
Cmd.CommandText = 'Incassi_CercaPerNdg'
Cmd.CommandType = adCmdStoredProc
Cmd.CommandTimeout = 15

Prm = win32com.client.Dispatch(r'ADODB.Parameter')
Prm = Cmd.CreateParameter('@Ndg',adInteger, adParamInput,8,Ndg)
Cmd.Parameters.Append (Prm)
Rst = win32com.client.Dispatch(r'ADODB.Recordset')
Rst.Open (Cmd)
while not Rst.EOF:
for i in range(Rst.Fields.__len__()):
if Rst.Fields.Item(i).Type == 135:
dati.append(Rst.Fields.Item(i).Value.Format("%d/%m/%Y"))
elif Rst.Fields.Item(i).Type == 6:
temp =
float((long(Rst.Fields.Item(i).Value[1])&0xFFFFFFFFL) |
(long(Rst.Fields.Item(i).Value[0])<<32)) /1e4
dati.append(locale.format('%.2f',temp, 1))
else:
pass
Rst.MoveNext()
Rst.Close
self.Cnn.Close
return dati

def GetData(self,Ndg=1036):
dati=[]
if not str(Ndg).isdigit():
raise NoDataError('Il codice cliente inserito non e numerico')
Cmd =win32com.client.Dispatch(r'ADODB.Command')
Cmd.ActiveConnection = self.Cnn
Cmd.CommandText = 'Anagrafe_CercaPerNdg'
Cmd.CommandType = adCmdStoredProc
Cmd.CommandTimeout = 15

Prm = win32com.client.Dispatch(r'ADODB.Parameter')
Prm = Cmd.CreateParameter('@Ndg',adInteger, adParamInput,8,Ndg)
Cmd.Parameters.Append (Prm)
Rst = win32com.client.Dispatch(r'ADODB.Recordset')
Rst.Open (Cmd)
if not Rst.EOF:
for i in range(Rst.Fields.__len__()):
if Rst.Fields.Item(i).Value == None:
dati.append(None)
elif Rst.Fields.Item(i).Type == 135:
dati.append(Rst.Fields.Item(i).Value.Format("%d/%m/%Y"))
elif Rst.Fields.Item(i).Type == 6:
temp =
float((long(Rst.Fields.Item(i).Value[1])&0xFFFFFFFFL) |
(long(Rst.Fields.Item(i).Value[0])<<32)) /1e4
dati.append(locale.format('%.2f',temp, 1))
elif Rst.Fields.Item(i).Type ==202 or
Rst.Fields.Item(i).Type ==203:
a= (Rst.Fields.Item(i).Value)
dati.append(a.encode('latin-1','ignore'))
else:
dati.append(Rst.Fields.Item(i).Value)
else:
Rst.Close
self.Cnn.Close
raise NoDataError('Il codice cliente inserito non e corretto')
Rst.Close
self.Cnn.Close
return dati

class Error(Exception):
pass

class NoDataError(Error):
def __init__(self, message):
self.message = message

def __str__(self):
return `self.message`

if __name__ == '__main__':
prova = DBConnect()
try:
a = prova.GetData()
b = prova.GetHeaders()
prova = DBConnect()
c = prova.GetReturn()
print b ,c
print '-'*20
for v in a:
if v:
print v
else:
print ''
except NoDataError,e :
print e
S.G.A S.p.A.
Nucleo Sistemi Informativi
Luca Calderano
-----Messaggio originale-----
Da: py***************@python.org
[mailto:py***************@python.org]Per conto di JZ
Inviato: lunedi 15 settembre 2003 13.14
A: py*********@python.org
Oggetto: Re: caching the sql queries
On Mon, 15 Sep 2003 12:55:15 +0200, "Luca Calderano"
<ca*******@sgaspa.it> wrote:
Is there any equivalent of caching sql queries for Python like ADOdb
for PHP? (For those who did not hear about ADODb and its feature :
http://phplens.com/adodb/caching.of.recordsets.html)


The Only way is using Com


What do you mean?

--
JZ
--
http://mail.python.org/mailman/listinfo/python-list
Jul 18 '05 #1
0 1755

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

Similar topics

6
by: JZ | last post by:
Is there any equivalent of caching sql queries for Python like ADOdb for PHP? (For those who did not hear about ADODb and its feature : http://phplens.com/adodb/caching.of.recordsets.html) -- JZ
0
by: Luca Calderano | last post by:
The Only way is using Com S.G.A S.p.A. Nucleo Sistemi Informativi Luca Calderano -----Messaggio originale----- Da: python-list-admin@python.org Per conto di JZ
0
by: DocFalken | last post by:
Hello, I'm running into some inconsistent query caching. Has anyone run into this and has a solution or better place to look? All of my queries don't violate the caching terms (no Now() or...
2
by: Martin Sarsale | last post by:
Dear All: Im looking for solutions (Free Software is better) to do query result caching. Thanks to the people from #postgresql I know that postgres doesn't do that by himself and the solution...
0
by: Ed | last post by:
Hi all, Have a strange situation regarding fragment caching. I've read the docs and kbs on this so it's either I've missed some key aspect of the implementation or there is a "gotcha" here that...
6
by: onnodb | last post by:
Hi all, While working on an Access UI to a MySQL database (which should be a reasonable, low-cost, flexible interface to the DB, better than web-based, much less costly than a full-fledged .NET...
4
by: Hermann | last post by:
My site is a bit slow showing the main page so I thought caching query result in PHP will improve performace. Then I read MySQL documentation and saw that MySQL does have a caching feature. So......
3
by: Bishop | last post by:
I have a treeview in my master page. It's built off a sql table that looks like this: TreeID, Name, ParentID 1,shoes,0 2,boots,0 3,slippers,0 4,shoe laces, 1 5, shoe soles, 1 6, boot laces,...
9
by: jehugaleahsa | last post by:
Hello: I am writing a cute little class that will cache queries against a database. Currently, I am implementing this by storing the command text, parameter values and generated DataRows. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.