No. There is standard SQL language, but this standard says only how SELECT, INSERT etc should work. There is nothing about .sql files. This way each DBMS vendor has his own ways of working with such files. In PostgreSQL you can easily run psql command line programm with your file as input. In Oracle world you can try to do the same using sqlplus but of course such .sql files will vary. In PostgreSQL you should set encoding of input file using non-standard SQL command that other vendors will report as error. For such things Oracle uses environment settings. With Oracle your .sql file for sqlplus must end with COMMIT; EXIT; etc. Even datetime string literals are different for each vendor. MS SQL uses {ts '...'} which will not work with Informix, PostgreSQL nor Oracle.
Shortly: it seems impossible to do such program for each database.
All you can do is to invite additional layer that will change your standard input file (add some header and footer, convert datetime literals etc). Then such prepared file can be run against command line tools given by database vendor, or by your specialized program able to execute such converted file.
EDIT:
It seems that you have different files for different databases, and even for different database versions. You can also use native programs that are able to run .sql file. So the only problem is to detect database and database version and execute proper file using proper native client. This is code in Jython (I often use JDBC, but you can use DB-API and Python db drivers):
def get_db_version(db):
dbname = ''
ver = ''
c = db.createStatement()
try:
rs = c.executeQuery("SELECT FIRST 1 DBINFO('version','full') FROM systables")
dbname = 'informix'
# IBM Informix Dynamic Server Version 11.50.FC4
except:
try:
rs = c.executeQuery("SELECT * FROM v$version WHERE banner LIKE 'Oracle%'")
dbname = 'oracle'
# Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
except:
try:
rs = c.executeQuery("SELECT version()")
dbname = 'postgresql'
# PostgreSQL 9.2.4 on ..., 64-bit
# PostgreSQL 9.3.0 on ..., 64-bit
except:
raise
if dbname:
while (rs.next()):
ver = rs.getString(1)
return dbname, ver
def select_sql_app_and_file():
import_app = None
ver_postfix = ''
dbname, ver = get_db_version(create_db_connection())
if dbname == 'postgresql':
import_app = 'psql'
if 'PostgreSQL 9.2' in ver:
import_app = 'psql92'
ver_postfix = '92'
elif dbname == 'oracle':
import_app = 'sqlplus'
if 'Release 11.' in ver:
import_app = 'sqlplus11'
ver_postfix = '11'
# ...
sql_file_name = 'import_' + dbname + ver_postfix + '.sql'
return import_app, sql_file_name
def run_sql_file():
import_app, sql_file_name = select_sql_app_and_file()
if import_app:
execute_import_app(import_app, sql_file_name)
sqlplus,psql?--!/usr/bin/program_that_handles_my_file), or better add special comment that shows for which version is this file.psqlfor the newest version,psql91for 9.1,psql92for 9.2 etc. Just prepare environment by making proper links, scripts, batches etc.