473,320 Members | 2,052 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,320 software developers and data experts.

Creating database structures in a portable way

Hi,

I am looking for a library that takes an XML file that specifies a
table structure, and generates the CREATE/DROP/ALTER SQL statements to
create the tables in the database.

In particular, I am trying to port a PHP application that currently
uses the AdoDB XML schema:
http://phplens.com/lens/adodb/docs-d....htm#xmlschema
Is there a way to do something similar with the DB-API modules in
Python?

Thanks,
-Samuel

Sep 18 '06 #1
4 1397
Samuel wrote:
Hi,

I am looking for a library that takes an XML file that specifies a
table structure, and generates the CREATE/DROP/ALTER SQL statements to
create the tables in the database.

In particular, I am trying to port a PHP application that currently
uses the AdoDB XML schema:
>http://phplens.com/lens/adodb/docs-d....htm#xmlschema

Is there a way to do something similar with the DB-API modules in
Python?
FWIW, there's a Python port of adodb:
http://phplens.com/lens/adodb/adodb-py-docs.htm

and parsing XML in Python is quite easy. So you could as well port the
AdoDB XML to Python too.

OTOH, there are other - possibly better (YMMV) - DB abstraction layers
in Python, like SQLAlchemy. And since the above solution requires
(re)writing the xml-parsing part, it might be worth rewriting it so it
knows how to generate SQLAlchemy schemas instead.

My 2 cents...

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Sep 18 '06 #2
FWIW, there's a Python port of adodb:
http://phplens.com/lens/adodb/adodb-py-docs.htm

and parsing XML in Python is quite easy. So you could as well port the
AdoDB XML to Python too.
That is exactly what I am trying to avoid. While implementing the
parser might be easy, you have to translate things into different
database flavors, caring about a bunch of things that I'd rather not
have to think about.
OTOH, there are other - possibly better (YMMV) - DB abstraction layers
in Python, like SQLAlchemy.
SQLAlchemy looks pretty good, but unfortunately apparently requires
shell access for installation (or at least, I have not found any other
solution covered in the docs), which I can not use. I need a solution
that can be shipped in a software package, and installed by simply
copying it to the server.
And since the above solution requires
(re)writing the xml-parsing part, it might be worth rewriting it so it
knows how to generate SQLAlchemy schemas instead.
Rewriting the schema is possible (I only want to keep it separated from
the code), so using SQLAlchemy's built in solution for generating
tables seems just fine. It's only the installation part.

Anyway, I am wondering; Python seems to include database adapters for
almost any important database, all with a unified API. Why would you
need another database abstraction on top of that?

Thanks,
-Samuel

Sep 18 '06 #3
Samuel a écrit :
>>FWIW, there's a Python port of adodb:
http://phplens.com/lens/adodb/adodb-py-docs.htm

and parsing XML in Python is quite easy. So you could as well port the
AdoDB XML to Python too.


That is exactly what I am trying to avoid. While implementing the
parser might be easy, you have to translate things into different
database flavors, caring about a bunch of things that I'd rather not
have to think about.
This I can understand pretty well - hence my suggestion of using
SQLAlchemy instead.
>
>>OTOH, there are other - possibly better (YMMV) - DB abstraction layers
in Python, like SQLAlchemy.


SQLAlchemy looks pretty good, but unfortunately apparently requires
shell access for installation (or at least, I have not found any other
solution covered in the docs), which I can not use. I need a solution
that can be shipped in a software package, and installed by simply
copying it to the server.
It doesn't use binaries AFAIK, so just copying should work as well.
>
>>And since the above solution requires
(re)writing the xml-parsing part, it might be worth rewriting it so it
knows how to generate SQLAlchemy schemas instead.

Rewriting the schema is possible (I only want to keep it separated from
the code),
Why ? Isn't your code supposed to use it ?
so using SQLAlchemy's built in solution for generating
tables seems just fine. It's only the installation part.
cf above.
Anyway, I am wondering; Python seems to include database adapters for
almost any important database, all with a unified API. Why would you
need another database abstraction on top of that?
A first point is that the DB-API doesn't hide the differences between
various SQL dialects. A second point is that DB-API requires you to
embed SQL statements as strings, while SQLAlchemy allow you to build
your SQL queries in pure Python. (and FWIW, if using an existing DB, you
don't even have to describe the schema a second time to use it). Well,
just start playing with it, and I really doubt you'll want to come back
to the embedded hand-written SQL !-)

My 2 cents
Sep 18 '06 #4
SQLAlchemy looks pretty good, but unfortunately apparently requires
shell access for installation (or at least, I have not found any other
solution covered in the docs), which I can not use.

It doesn't use binaries AFAIK, so just copying should work as well.
Indeed, from browsing the package it seems like a pure Python solution.
I installed it (but didn't test it yet because I have no code to drive
it yet).
Rewriting the schema is possible (I only want to keep it separated from
the code),

Why ? Isn't your code supposed to use it ?
It often makes sense to use meta languages to enforce clean separation
of logic. In my experience it is helpful to separate the database logic
from the application logic.
A first point is that the DB-API doesn't hide the differences between
various SQL dialects.
I see.
A second point is that DB-API requires you to
embed SQL statements as strings, while SQLAlchemy allow you to build
your SQL queries in pure Python.
I'd rather not rewrite every single Sql statement into Python, since it
would

1. replace code that has already proven to work by something untested.
2. add yet another abstraction, at the cost of performance.

Luckily, SQLAlchemy also lets me use SQL statements directly.
(and FWIW, if using an existing DB, you
don't even have to describe the schema a second time to use it). Well,
just start playing with it, and I really doubt you'll want to come back
to the embedded hand-written SQL !-)
If I ever write something from scratch I'll use it.

Thanks for your comments, this was very helpful.

-Samuel

Sep 19 '06 #5

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

Similar topics

11
by: Fred Bennett | last post by:
I have a simulation project in which data can naturally be held in structures for processing. There are calls to multiple functions involved. Execution speed is an issue. Do I take a big hit for...
6
by: Dim St Thomas | last post by:
I am a developer working on a database client program. I am testing this program on a Windows XP machine (1.5 GHz AMD chip, 480 Mb RAM, 60 Gb disk) This machine has Oracle 9.2.0.1.0 and RedBrick...
11
by: Bradford Chamberlain | last post by:
I work a lot with multidimensional arrays of dynamic size in C, implementing them using a single-dimensional C array and the appropriate multipliers and offsets to index into it appropriately. I...
6
by: Everton da Silva Marques | last post by:
Hi, I need to allocate, using malloc(), a single memory block to hold two structures and a variable length string. Is it safe (portable, alignment-wise) to sum up the sizeof's of those...
10
by: Roman Mashak | last post by:
Hello, All! Could you please explain me how is the padding of 'structure' fields is made? For example: struct { char a1; int a2;
18
by: rdemyan via AccessMonster.com | last post by:
Here's my plan for creating nightly backups of the production back-end file (the IT staff in their infinite wisdom have prevented use of Windows Scheduler and users do not have administrative...
11
by: skumar434 | last post by:
Hi everybody, I am faceing problem while assigning the memory dynamically to a array of structures . Suppose I have a structure typedef struct hom_id{ int32_t nod_de; int32_t hom_id;
17
Motoma
by: Motoma | last post by:
This article is cross posted from my personal blog. You can find the original article, in all its splendor, at http://motomastyle.com/creating-a-mysql-data-abstraction-layer-in-php/. Introduction:...
3
by: Bartholomew Simpson | last post by:
I am writing some C++ wrappers around some legacy C ones - more specifically, I am providing ctors, dtors and assignment operators for the C structs. I have a ton of existing C code that uses...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.