473,802 Members | 2,117 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DB beginner help

1. Is there any HOW-TO documentation about DB API except PEP 249?

2. How are you supposed to write DB-driver independent code when each
driver has its own, possibly different from any other, paramstyle
('qmark', 'numeric', etc..)?

In Perl I always use question marks and have no trouble switching the
application between different databases. How do you guys do it in Python
(of course, without rewriting all queries?)
Jul 18 '05 #1
4 1348

"Zeljko Vrba" <mo****@fly.srk .fer.hr> wrote in message
news:slrnch3ms4 .7mn.mo****@fly .srk.fer.hr...
In Perl I always use question marks and have no trouble switching the
application between different databases. How do you guys do it in Python
(of course, without rewriting all queries?)


Do your database work from a "connection " object and use a database-specific
function to create that object. Most of the time that will work with several
SQL databases.

I use a class wrapper for the specific database that is given a connection
object when the class is initialised. The wrapper hides the lameness of SQL
in some obvious situations - f.ex calculating a running balance like a bank
statement is easiest done by the application, but procedures will work also.

I also think that a dicts are a good way to "paste" information into SQL
query strings

It goes sort of like:

# open the stock database and insert the information.
try:
cursor = self.conn.curso r()
cursor.execute(
"""
INSERT INTO stocks (ticker, exchange, stockName,
stockDescriptio n)
VALUES ('%(Ticker)s', '%(Exchange)s', '%(stockName)s,
'%(stockDescrip tion)s)
""" % colkey)
except:
log.error(
"""
Failed to create new Entry for %(Ticker)s, on %(Exchange)s'
""" % colkey, exc_info=True)
raise
else:
# account opened.
self.commit(Tru e)
log.info('Entry Created for %(Ticker)s, on %(Exchange)s'
% colkey)
# done
return None

...... Funny how every amateur programmer seem to dabble in stocks :-)

The "connection " is the standardised way of representing a database as an
object in Python. *How* to get the connection is database-dependent. You
might also be bitten by the various interpretations of SQL in the underlying
databases; Time/Date fields are always dubious, some databases only work
with few data types, even Strings Only(!), and some corners of SQL like
CHECK constraints (PySQLite) and even FOREIGN KEY constraints (Seen it on
something, I discarded for that reason - GadFly?) may not be enforced!


Jul 18 '05 #2

"Frithiof Andreas Jensen" <frithiof.jense n@die_spammer_d ie.ericsson.com >
wrote in message news:ce******** **@newstree.wis e.edt.ericsson. se...

BTW, the 's in the query string are wrong.
Jul 18 '05 #3
On 2004-08-05, Zeljko Vrba <mo****@fly.srk .fer.hr> wrote:
2. How are you supposed to write DB-driver independent code when each
driver has its own, possibly different from any other, paramstyle
('qmark', 'numeric', etc..)?
This recipe might help:

http://aspn.activestate.com/ASPN/Coo.../Recipe/278612

I haven't tried it.
In Perl I always use question marks and have no trouble switching the
application between different databases. How do you guys do it in Python
(of course, without rewriting all queries?)


pyformat is the most useful IMO, e.g.

cursor.execute(
"insert into foo (baz, quux) values (%(baz)s, %(quux)s)",
{'parrot' : 'deceased', 'quux' : "O'Reilly", 'baz' : 1})

The values for 'baz' and 'quux' will be interpolated and quoted correctly,
and 'parrot' will be ignored.

A few adapters have a dictfetch method, but for those that don't, getting
your data out in dict form is a two liner:

fieldnames = [tup[0] for tup in cursor.descript ion]
dictrows = [dict(zip(fieldn ames, row)) for row in cursor.fetchall ()]

Dave Cook
Jul 18 '05 #4
Hello,

I want to use Python for Image proccessing.
I need the following capabilities:

1. To be able to read and WRITE an AVI file frame by frame.
2. To be able to access each fram as a simple matrix.

I tried to search for that in google but could not find something
intuitive and simple.

The matrices part is important since iamge processing is done through
matrices manipulation.

MATLAB is an example of a tool with scripting capabilities in which you
can do that in a simple way.

Is Python adequate for that?

Thanks,
Nir
Jul 18 '05 #5

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

Similar topics

3
1680
by: JHenstay | last post by:
I've been doing quite alot of reading on C++ and classes, however, everything I read just talks about the code itself and not the location of the code. My question is, what if you want to seperate classes into their own CPP files, what changes are needed to the files and how do you actually compile and build an executable. For instance, let's say I have the following all in one file, it would compile and link into an executable fine:
4
1252
by: Curt Lashley via .NET 247 | last post by:
I am totally new to .net So far, I hate it. I been programming vb since vb3 and .net took a 1 line program and made it a 47 lines program filled with stuf that appears meaningless... ok, I know it's not, but it seams that way. Forgive me, I'm old and stuck in my ways. I did not want to re-learn how the wheel works, but M$ is forcing it. Unless I switch to "Real Basic" Is there a source of sample apps that one can tap into for examples....
1
1314
by: Mike Bell | last post by:
Ok.... I'm trying to build my own custom calendar control for a first custom control practice project. For this control I'm deriving from the table class. I have created a new class called CalCell that is derived from the TableCell class that adds some methods and events. Being th newby that I am, I can't figure out how to access this class from Table.Rows. i.e Table1.Row.CalCell. Now I'm thinking I have to create my own CalTable class,...
1
1206
by: Phil | last post by:
Hi I admit it, I am a total vb beginner. I thought I'd get hold of a copy to see if I could resolve a simple problem we have. I am looking to search AD for user objects for reporting purposes, and have read numerous code samples etc on MSDN, and have tried to use these but with no success. Every time I try to 'run' my code I get build errors, and I am told that
1
1177
by: Gaz | last post by:
Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit > Hi all > > I am trying to write a program that opens a text file and manipulates the data. > > I have managed to open the text file into a textbox1 as a string > i now wish to add code to a button that will find a line in the
33
2427
by: aaron | last post by:
I have a question in my class.. hoping to get some help I need to create a program that will print firstName middleName lastName then their initials User will input: John Smith Doe Output: John
5
1113
by: allenj3 | last post by:
What is a good online resource for beginners with ASP? In the past I've mostly worked with Office based applications and VB and I'm having a really hard time figuring out ASP on my own. Any help would be greatly appreciated. Thanks!
4
4831
by: PhreakRox | last post by:
Hello, I am new to c++ Win32 coding, actually this is the first time Ive really tried to make a program with it. I was trying to create a "love calculator" program, this exerpt is tha part which compares the length of the 2 different names. It does not compile, and instead gives me 3 errors and 4 warnings, could someone please tell me what I am doing wrong? Help would be greatly appreciated. Errors/Warnings: Warning 1 warning C4267:...
4
1584
by: corky20 | last post by:
Can someone help...i've only started learning visual basic and i'm pretty new to programming(i know but everyones been there at one point) and need help with a question! A man is paid at the hourly rate of £8 per hour for the first 35 hours worked. Thereafter overtime is paid at time and a half for the next 10 hours and double time for further hours worked. Design and write a program to input the number of hours worked per week, calculate...
0
9699
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
9562
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,...
0
10304
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10285
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,...
0
9114
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6838
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
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4270
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
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.