Changeset: 848596d8ac58 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=848596d8ac58 Added Files: clients/python/examples/mclient.py clients/python/monetdb/exceptions.py clients/python/monetdb/sql/monetize.py clients/python/monetdb/sql/pythonize.py clients/python/monetdb/sql/types.py Removed Files: clients/python/monetdb/mclient.py clients/python/monetdb/monetdb_exceptions.py clients/python/monetdb/sql/type_codes.py Modified Files: clients/python/examples/perf.py clients/python/monetdb/__init__.py clients/python/monetdb/mapi.py clients/python/monetdb/sql/__init__.py clients/python/monetdb/sql/connections.py clients/python/monetdb/sql/converters.py clients/python/monetdb/sql/cursors.py clients/python/test/capabilities.py clients/python/test/dbapi20.py Branch: default Log Message:
moved to new structure, made string escaping much faster diffs (truncated from 1660 to 300 lines): diff --git a/clients/python/examples/mclient.py b/clients/python/examples/mclient.py new file mode 100755 --- /dev/null +++ b/clients/python/examples/mclient.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python + +# The contents of this file are subject to the MonetDB Public License +# Version 1.1 (the "License"); you may not use this file except in +# compliance with the License. You may obtain a copy of the License at +# http://www.monetdb.org/Legal/MonetDBLicense +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +# License for the specific language governing rights and limitations +# under the License. +# +# The Original Code is the MonetDB Database System. +# +# The Initial Developer of the Original Code is CWI. +# Portions created by CWI are Copyright (C) 1997-July 2008 CWI. +# Copyright August 2008-2012 MonetDB B.V. +# All Rights Reserved. + +# + +import sys +import getopt + +from monetdb import mapi + +def main() : + hostname = 'localhost' + port = '50000' + username = 'monetdb' + password = 'monetdb' + language = 'sql' + database = '' + encoding = None + + opts, args = getopt.getopt(sys.argv[1:], '', + ['host=', 'port=', 'user=', 'passwd=', + 'language=', 'database=', 'encoding=']) + for o, a in opts: + if o == '--host': + hostname = a + elif o == '--port': + port = a + elif o == '--user': + username = a + elif o == '--passwd': + password = a + elif o == '--language': + language = a + elif o == '--database': + database = a + elif o == '--encoding': + encoding = a + + if encoding is None: + import locale + encoding = locale.getlocale()[1] + if encoding is None: + encoding = locale.getdefaultlocale()[1] + + s = mapi.Server() + + s.connect(hostname = hostname, + port = int(port), + username = username, + password = password, + language = language, + database = database) + print "#mclient (python) connected to %s:%d as %s" % (hostname, int(port), username) + fi = sys.stdin + prompt = '%s>' % language + + sys.stdout.write(prompt.encode('utf-8')) + line = fi.readline() + if encoding != 'utf-8': + prompt = unicode(prompt, 'utf-8').encode(encoding, 'replace') + while line and line != "\q\n": + if encoding != 'utf-8': + line = unicode(line, encoding).encode('utf-8') + res = s.cmd('s' + line) + if encoding != 'utf-8': + res = unicode(res, 'utf-8').encode(encoding, 'replace') + print res + sys.stdout.write(prompt) + line = fi.readline() + + s.disconnect() + +if __name__ == "__main__": + main() diff --git a/clients/python/examples/perf.py b/clients/python/examples/perf.py --- a/clients/python/examples/perf.py +++ b/clients/python/examples/perf.py @@ -34,11 +34,9 @@ except ImportError: sys.path.append(parent) import monetdb.sql -for i in (10, 100, 1000, 10000): - t = time.time() - x = monetdb.sql.connect(database="demo") - c = x.cursor() - c.arraysize=i - c.execute('select * from tables, tables, tables') - results = c.fetchall() - print i, time.time() - t +t = time.time() +x = monetdb.sql.connect(database="demo") +c = x.cursor() +c.arraysize=10000 +c.execute('select * from tables, tables') +results = c.fetchall() diff --git a/clients/python/monetdb/__init__.py b/clients/python/monetdb/__init__.py --- a/clients/python/monetdb/__init__.py +++ b/clients/python/monetdb/__init__.py @@ -14,3 +14,20 @@ # Portions created by CWI are Copyright (C) 1997-July 2008 CWI. # Copyright August 2008-2012 MonetDB B.V. # All Rights Reserved. + +""" +This is the MonetDB Python API. + +The MAPI (MonetDB API) related code is in monetdb.mapi. + +The SQL related code is in monetdb.sql. + +To set up a connection use monetdb.sql.connect() + +""" +from monetdb import sql +from monetdb import mapi + +__all__ = ["sql", "mapi"] + +connect = sql.connect \ No newline at end of file diff --git a/clients/python/monetdb/exceptions.py b/clients/python/monetdb/exceptions.py new file mode 100644 --- /dev/null +++ b/clients/python/monetdb/exceptions.py @@ -0,0 +1,88 @@ +# The contents of this file are subject to the MonetDB Public License +# Version 1.1 (the "License"); you may not use this file except in +# compliance with the License. You may obtain a copy of the License at +# http://www.monetdb.org/Legal/MonetDBLicense +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +# License for the specific language governing rights and limitations +# under the License. +# +# The Original Code is the MonetDB Database System. +# +# The Initial Developer of the Original Code is CWI. +# Portions created by CWI are Copyright (C) 1997-July 2008 CWI. +# Copyright August 2008-2012 MonetDB B.V. +# All Rights Reserved. + +class Warning(StandardError): + """Exception raised for important warnings like data + truncations while inserting, etc. It must be a subclass of + the Python StandardError (defined in the module + exceptions).""" + pass + +class Error(StandardError): + """Exception that is the base class of all other error + exceptions. You can use this to catch all errors with one + single 'except' statement. Warnings are not considered + errors and thus should not use this class as base. It must + be a subclass of the Python StandardError (defined in the + module exceptions).""" + pass + + +class InterfaceError(Error): + """Exception raised for errors that are related to the + database interface rather than the database itself. It + must be a subclass of Error.""" + pass + +class DatabaseError(Error): + """Exception raised for errors that are related to the + database. It must be a subclass of Error.""" + pass + +class DataError(DatabaseError): + """Exception raised for errors that are due to problems with + the processed data like division by zero, numeric value + out of range, etc. It must be a subclass of DatabaseError.""" + pass + +class OperationalError(DatabaseError): + """Exception raised for errors that are related to the + database's operation and not necessarily under the control + of the programmer, e.g. an unexpected disconnect occurs, + the data source name is not found, a transaction could not + be processed, a memory allocation error occurred during + processing, etc. It must be a subclass of DatabaseError.""" + pass + +class IntegrityError(DatabaseError): + """Exception raised when the relational integrity of the + database is affected, e.g. a foreign key check fails. It + must be a subclass of DatabaseError.""" + pass + +class InternalError(DatabaseError): + """Exception raised when the database encounters an internal + error, e.g. the cursor is not valid anymore, the + transaction is out of sync, etc. It must be a subclass of + DatabaseError.""" + pass + +class ProgrammingError(DatabaseError): + """Exception raised for programming errors, e.g. table not + found or already exists, syntax error in the SQL + statement, wrong number of parameters specified, etc. It + must be a subclass of DatabaseError.""" + pass + +class NotSupportedError(DatabaseError): + """Exception raised in case a method or database API was used which is not + supported by the database, e.g. requesting a .rollback() on a connection + that does not support transaction or has transactions turned off. It must + be a subclass of DatabaseError.""" + pass + + diff --git a/clients/python/monetdb/mapi.py b/clients/python/monetdb/mapi.py --- a/clients/python/monetdb/mapi.py +++ b/clients/python/monetdb/mapi.py @@ -27,7 +27,7 @@ import platform from cStringIO import StringIO -from monetdb.monetdb_exceptions import * +from monetdb.exceptions import * logger = logging.getLogger("monetdb") diff --git a/clients/python/monetdb/mclient.py b/clients/python/monetdb/mclient.py deleted file mode 100755 --- a/clients/python/monetdb/mclient.py +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/env python - -# The contents of this file are subject to the MonetDB Public License -# Version 1.1 (the "License"); you may not use this file except in -# compliance with the License. You may obtain a copy of the License at -# http://www.monetdb.org/Legal/MonetDBLicense -# -# Software distributed under the License is distributed on an "AS IS" -# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the -# License for the specific language governing rights and limitations -# under the License. -# -# The Original Code is the MonetDB Database System. -# -# The Initial Developer of the Original Code is CWI. -# Portions created by CWI are Copyright (C) 1997-July 2008 CWI. -# Copyright August 2008-2012 MonetDB B.V. -# All Rights Reserved. - -# - -import sys -import getopt - -from monetdb import mapi - -def main(argv) : - hostname = 'localhost' - port = '50000' - username = 'monetdb' - password = 'monetdb' - language = 'sql' - database = '' - encoding = None - - opts, args = getopt.getopt(argv[1:], '', - ['host=', 'port=', 'user=', 'passwd=', - 'language=', 'database=', 'encoding=']) - for o, a in opts: - if o == '--host': - hostname = a - elif o == '--port': - port = a - elif o == '--user': - username = a - elif o == '--passwd': - password = a - elif o == '--language': - language = a _______________________________________________ Checkin-list mailing list Checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list