I: caching the sql queries

L

Luca Calderano

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').Value.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: (e-mail address removed)
[mailto:p[email protected]]Per conto di JZ
Inviato: lunedi 15 settembre 2003 13.14
A: (e-mail address removed)
Oggetto: Re: caching the sql queries


The Only way is using Com

What do you mean?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,117
Latest member
Matilda564
Top