looking for ocbc example

C

Carl K

I am sure this is what I want:
http://www.python.org/topics/database/docs.html
"The documentation for the PythonWin ODBC module."

but it is 404.

google isn't being nice.

Anyone know where I can find some simple examples?

I have used odbc in other environments, so just need to know what modules, and
the lines to connect and execute a sql command.

It seems there are 2 odbc modules - pyOdbc and mxOdbc - anyone know the difference?

Carl K
 
T

Tim Golden

Carl said:
It seems there are 2 odbc modules - pyOdbc and mxOdbc - anyone know the difference?

In short, pyodbc is open source; mxOdbc requires a commercial license.
pyodbc is a newcomer, but appears to work for everything I've thrown
at it (which is not much). mxOdbc has been around longer, and is sure
to be a more mature product. It may offer more features & functionality.

Unless you've got specific requirements (for example, commercial and/or
bleeding-edge support) I suggest you start with pyodbc. You should be
able to switch quite easily to mxODBC if that seems necessary later.

TJG
 
J

jay graves

In short, pyodbc is open source; mxOdbc requires a commercial license.
pyodbc is a newcomer, but appears to work for everything I've thrown
at it (which is not much). mxOdbc has been around longer, and is sure
to be a more mature product. It may offer more features & functionality.

There is also a brand new module 'ceODBC'.
http://ceodbc.sourceforge.net/

I haven't used it yet but I want to give it a try.

....
Jay
 
M

M.-A. Lemburg

Carl said:
I am sure this is what I want:
http://www.python.org/topics/database/docs.html
"The documentation for the PythonWin ODBC module."

but it is 404.

google isn't being nice.

Anyone know where I can find some simple examples?

I have used odbc in other environments, so just need to know what modules, and
the lines to connect and execute a sql command.

Here's a very simple example for mxODBC:

# mxODBC is available from http://www.egenix.com/products/python/mxODBC/:

# On Windows:
from mx.ODBC import Windows as Database

# On Mac OS X:
from mx.ODBC import iODBC as Database

# On Linux/BSD/etc.:
from mx.ODBC import unixODBC as Database
# or
from mx.ODBC import iODBC as Database

# Open a connection to the database
connection = Database.DriverConnect('DSN=<datasourcename>;'
'UID=<username>;'
'PWD=<password>;'
'KEYWORD=<value>')
# replace the values accordingly, add new keyword-value pairs as
# necessary for your data source; data sources are configured
# in the ODBC manager

# Create a cursor; this is used to execute commands
cursor = connection.cursor()

# Create a table
cursor.execute('CREATE TABLE mxodbcexample1 '
' (id integer, name varchar(10), data varchar(254))')
# this command does not create a result set, so there's nothing
# to fetch from the database; however in order to make the
# change permanent, we need to commit the change
connection.commit()

# Prepare some data rows to add to the table, ie. a list of tuples
rows = []
for i in range(42):
name = 'name-%i' % i
data = 'value-%i' % i
rows.append((i, name, data))

# Add the data in one go; the values from the tuples get assigned
# to the ?-mark parameter markers in the SQL statement based on
# their position and the SQL statement is executed once for
# each tuple in the list of rows
cursor.executemany('INSERT INTO mxodbcexample1 VALUES (?,?,?)',
rows)

# If you apply changes to the database, be sure to commit or
# rollback your changes; a call to .commit() or .rollback()
# will implicitly start a new transaction
connection.commit()

# Now fetch some data rows
from_id = 40
to_id = 42
cursor.execute('SELECT * FROM mxodbcexample1'
' WHERE (id >= ?) and (id < ?)',
(from_id, to_id))

# Fetch the results
for i, row in enumerate(cursor.fetchall()):
print 'Row %i: %r' % (i, row)

# Remove the table again
cursor.execute('DROP TABLE mxodbcexample1')
connection.commit()

# Close the connection
connection.close()


With MS Access this gives:

Row 0: (40, 'name-40', 'value-40')
Row 1: (41, 'name-41', 'value-41')

--
Marc-Andre Lemburg
eGenix.com

Professional Python Software directly from the Source________________________________________________________________________

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::
 
C

Carl K

jay said:
There is also a brand new module 'ceODBC'.
http://ceodbc.sourceforge.net/

I haven't used it yet but I want to give it a try.

I tried it, and it worked better than pyodbc. (better is not exactly right.
there was some weird bug in the ctree odbc driver, and the author of ceODBC gave
me a workaround.)

Carl K

Carl K
 
T

Tim Golden

Carl said:
I tried it, and it worked better than pyodbc. (better is not exactly right.
there was some weird bug in the ctree odbc driver, and the author of ceODBC gave
me a workaround.)

All right, I'm a little perplexed as to whether "better" here
refers to the admirable response of the ceOBDC author or to
some other factors which demonstrate ceODBC's superiority.

I've not really got the opportunity to pit them against each
other so to speak, but I'd love to hear from someone who had.

TJ
 
S

supercooper

All right, I'm a little perplexed as to whether "better" here
refers to the admirable response of the ceOBDC author or to
some other factors which demonstrate ceODBC's superiority.

I've not really got the opportunity to pit them against each
other so to speak, but I'd love to hear from someone who had.

TJ

Just tried ceODBC the other day (on XP), and it worked like a charm
connecting SqlServer and DB2. Here's SqlServer:
.... print each
....
('GILL #1-18', 33.095599, -92.38563)
('HOW #2-7', 35.10155, -91.48824)
('JKK #11-13', 34.09130, -93.45256)

Simple! Very similar syntax to mxODBC.
 
D

Dennis Lee Bieber

Most adapters work in iterator mode -- no need to use the
..fetchall(), just "for each in c"
Simple! Very similar syntax to mxODBC.

Similarly, most of the database adapters follow the DB-API spec --
so follow the same set of calls; the only real differences are those
involved with parameterized queries (is it ?, %s, etc.) and
thread/module sharing level.
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
Joined
Nov 26, 2010
Messages
8
Reaction score
0
Re: Starting a new Savings account

I appreciate the concern which is been rose.
======================
 
Joined
Nov 26, 2010
Messages
8
Reaction score
0
The things need to be sorted out because it is about the individual but it can be with everyone.
======================
 
Joined
Nov 26, 2010
Messages
8
Reaction score
0
I like this particular article It gives me an additional input on the information around the world Thanks a lot and keep going with posting such information.
======================
 
Joined
Nov 26, 2010
Messages
8
Reaction score
0
Re: Starting a new Savings account

A very smart and diplomatic answer. It’s really appreciable and general.
======================
 
Joined
Nov 26, 2010
Messages
8
Reaction score
0
I subscribe to Insider Score, and that is correct there has been scant insider buying.
======================
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top