A few days ago I asked how to use xsql, as I have a large number of SQL
statements to create the database schema and then insert the data
values.  I was pointed to the db loader.

This is all well and good as sapdb to sapdb transfers, migrations, etc
go.  But I (and a fair few others, judging by the traffic on the list)
need to convert a few Access databases, or SQLserver databases, or... 
To get the import into SAPdb working with the loader would demand that I
write my own version of the unload tool.  This is a nontrivial task. 
SQL is a well understood tool, and there are plenty of tested SQL
routines around for me to use to download the data.  I am amazed that
SAP should consider SQL an inappropriate tool to input into an RDBMS.

To that end, I have hacked together a short python script to read and
execute an arbitrary number of SQL statements.  It expects the
statements to be in a text file, separated by semicolons.  If you have a
file that would work in Oracle, or SQL server, or postgresql, etc, then
it should work in this script.  Obviously you will have to manipulate
the data types, INT instead of INT4, for instance.

This is a real hack.  I'm a complete novice at Python, my day job is
abap.  This is provided free, no warranties provided, use at your own
risk, etc.  If any real Python l33t Haxors want to take this and improve
it into a real tool, I'd be very happy to use the result ;-)

Regards

Alan Graham

#!/usr/bin/python
#
# x_sql.py   call as x_sql.py <sql_text_file>
#

import sys

import sapdb

user = 'USER'
pwd = 'password'
dbname = 'your_db'
host = 'localhost'
filename = sys.argv [1]

session = sapdb.connect (user, pwd, dbname, host)

f = open (filename)
lines = f.readlines()

sql = ''
for l in lines:
        sql = sql + l[:-1]
        if len(sql) > 0 and ';' in sql[-1]:
                result = session.sql(sql[:-1])
                print result
                sql = ''

session.commit ()
session.release ()
print '\nSession released'

_______________________________________________
sapdb.general mailing list
[EMAIL PROTECTED]
http://listserv.sap.com/mailman/listinfo/sapdb.general

Reply via email to