Changeset: 0980a3c1f81c for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=0980a3c1f81c
Added Files:
        monetdb5/modules/mal/Tests/batpartition.mal
        monetdb5/modules/mal/Tests/batpartition.stable.err
        monetdb5/modules/mal/Tests/batpartition.stable.out
        sql/test/BugTracker-2013/Tests/between.Bug-3259.sql
        sql/test/BugTracker-2013/Tests/between.Bug-3259.stable.err
        sql/test/BugTracker-2013/Tests/between.Bug-3259.stable.out
        sql/test/BugTracker-2013/Tests/between.Bug-3259.stable.out.single
        sql/test/BugTracker-2013/Tests/correlated_select.Bug-3250.sql
        sql/test/BugTracker-2013/Tests/correlated_select.Bug-3250.stable.err
        sql/test/BugTracker-2013/Tests/correlated_select.Bug-3250.stable.out
        sql/test/BugTracker-2013/Tests/groupby_on_value_view.Bug-3264.sql
        sql/test/BugTracker-2013/Tests/groupby_on_value_view.Bug-3264.stable.err
        sql/test/BugTracker-2013/Tests/groupby_on_value_view.Bug-3264.stable.out
        sql/test/BugTracker-2013/Tests/select-view-view.Bug-3245.sql
        sql/test/BugTracker-2013/Tests/select-view-view.Bug-3245.stable.err
        sql/test/BugTracker-2013/Tests/select-view-view.Bug-3245.stable.out
        sql/test/BugTracker-2013/Tests/stddev-group.Bug-3257.sql
        sql/test/BugTracker-2013/Tests/stddev-group.Bug-3257.stable.err
        sql/test/BugTracker-2013/Tests/stddev-group.Bug-3257.stable.out
        sql/test/bugs/Tests/emili.sql
        sql/test/bugs/Tests/emili.stable.err
        sql/test/bugs/Tests/emili.stable.out
        sql/test/bugs/Tests/polymorphism.sql
        sql/test/bugs/Tests/polymorphism.stable.err
        sql/test/bugs/Tests/polymorphism.stable.out
Removed Files:
        sql/test/concurrent/Tests/crash_on_concurrent_use.SF-1411926.sql
Modified Files:
        README
        clients/python2/monetdb/control.py
        clients/python2/monetdb/sql/converters.py
        clients/python2/monetdb/sql/cursors.py
        clients/python2/monetdb/sql/monetize.py
        clients/python2/test/capabilities.py
        clients/python2/test/control.py
        clients/python2/test/dbapi20.py
        clients/python2/test/test_control.py
        clients/python3/monetdb/control.py
        clients/python3/monetdb/sql/converters.py
        clients/python3/monetdb/sql/cursors.py
        clients/python3/monetdb/sql/monetize.py
        clients/python3/test/capabilities.py
        clients/python3/test/run.sh
        clients/python3/test/runtests.py
        clients/python3/test/test_control.py
        configure.ag
        gdk/gdk_batop.c
        gdk/gdk_heap.c
        gdk/gdk_logger.c
        gdk/gdk_relop.mx
        gdk/gdk_sample.c
        gdk/gdk_setop.mx
        monetdb5/ChangeLog.Feb2013
        monetdb5/extras/jaql/jaqlscenario.c
        monetdb5/extras/mal_optimizer_template/Tests/opt_sql_append.stable.out
        monetdb5/mal/mal_dataflow.c
        monetdb5/modules/kernel/group.mx
        monetdb5/modules/mal/Tests/All
        monetdb5/modules/mal/Tests/partition.stable.out
        monetdb5/modules/mal/batExtensions.c
        monetdb5/modules/mal/mal_mapi.c
        monetdb5/modules/mal/tablet.c
        monetdb5/optimizer/Tests/tst4631.stable.out
        monetdb5/optimizer/opt_centipede.c
        monetdb5/optimizer/opt_matpack.c
        monetdb5/optimizer/opt_pipes.c
        monetdb5/optimizer/opt_pushselect.c
        monetdb5/optimizer/opt_support.c
        monetdb5/optimizer/opt_wrapper.c
        sql/backends/monet5/UDF/Tests/udf-fuse.stable.out
        sql/backends/monet5/UDF/Tests/udf-reverse.stable.out
        sql/backends/monet5/rel_bin.c
        sql/backends/monet5/sql.mx
        sql/backends/monet5/sql_gencode.c
        sql/backends/monet5/sql_optimizer.c
        sql/backends/monet5/sql_scenario.c
        sql/common/sql_types.c
        sql/include/sql_catalog.h
        sql/jdbc/tests/Tests/Test_Dobjects.stable.out
        sql/server/rel_optimizer.c
        sql/server/rel_select.c
        sql/server/sql_mvc.c
        sql/storage/bat/bat_storage.c
        sql/storage/store.c
        sql/test/BugTracker-2009/Tests/POWER_vs_prod.SF-2596114.stable.out
        
sql/test/BugTracker-2009/Tests/use_order_column_first.SF-2686008.stable.out
        sql/test/BugTracker-2011/Tests/func_iter_vs_bulk.Bug-2826.stable.out
        sql/test/BugTracker-2012/Tests/predicate_select.Bug-3090.stable.out
        
sql/test/BugTracker-2012/Tests/predicate_select.Bug-3090_nogeom.stable.out
        
sql/test/BugTracker-2012/Tests/rewrite_like_into_likesubselect.Bug-3179.stable.out
        sql/test/BugTracker-2013/Tests/All
        sql/test/BugTracker/Tests/explain.SF-1739353.stable.out
        sql/test/BugTracker/Tests/jdbc_no_debug.SF-1739356.stable.out
        sql/test/BugTracker/Tests/jdbc_no_debug.SF-1739356.stable.out.32bit
        sql/test/Tests/setoptimizer.stable.out
        sql/test/bugs/Tests/All
        sql/test/concurrent/Tests/crash_on_concurrent_use.SF-1411926.SQL.py
        sql/test/concurrent/Tests/crash_on_concurrent_use.SF-1411926.stable.out
        sql/test/mapi/Tests/php_monetdb.stable.out
        sql/test/mapi/Tests/php_monetdb_nogeom.stable.out
        sql/test/mapi/Tests/python2_test_monetdb_sql.stable.err
        sql/test/mapi/Tests/python3_test_monetdb_sql.stable.err
        sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out
        tools/mserver/mserver5.1
Branch: ssdb
Log Message:

merged from Feb2013


diffs (truncated from 5417 to 300 lines):

diff --git a/clients/python2/monetdb/control.py 
b/clients/python2/monetdb/control.py
--- a/clients/python2/monetdb/control.py
+++ b/clients/python2/monetdb/control.py
@@ -1,39 +1,83 @@
 
 from monetdb import mapi
+from monetdb.exceptions import OperationalError, InterfaceError
+
 
 def parse_statusline(line):
-    split = line.split(',')
+    """
+    parses a sabdb format status line. Support v1 and v2.
+
+    """
+    if not line.startswith('=sabdb:'):
+        raise OperationalError('wrong result recieved')
+
+    prot_version, rest = line.split(":", 2)[1:]
+
+    if prot_version not in ["1", "2"]:
+        raise InterfaceError("unsupported sabdb protocol")
+    else:
+        prot_version = int(prot_version)
+
+    subparts = rest.split(',')
+    sub_iter = iter(subparts)
     info = {}
-    info['path'] = split[0]
-    info['name'] = info['path'].split("/")[-1]
-    info['locked'] = split[1] == ("1")
-    info['state'] = int(split[2])
-    info['scenarios'] = split[3].split("'")
-    info['connections'] = split[4].split("'")
-    info['start_counter'] = int(split[5])
-    info['stop_counter'] = int(split[6])
-    info['crash_counter'] = int(split[7])
-    info['avg_uptime'] = int(split[8])
-    info['max_uptime'] = int(split[9])
-    info['min_uptime'] = int(split[10])
-    info['last_crash'] = int(split[11])
-    info['lastStart'] = int(split[12])
-    info['crash_avg1'] = split[13] == ("1")
-    info['crash_avg10'] = float(split[14])
-    info['crash_avg30'] = float(split[15])
+
+    info['name'] = sub_iter.next()
+    info['path'] = sub_iter.next()
+    info['locked'] = sub_iter.next() == "1"
+    info['state'] = int(sub_iter.next())
+    info['scenarios'] = sub_iter.next().split("'")
+    if prot_version == 1:
+        sub_iter.next()
+    info['start_counter'] = int(sub_iter.next())
+    info['stop_counter'] = int(sub_iter.next())
+    info['crash_counter'] = int(sub_iter.next())
+    info['avg_uptime'] = int(sub_iter.next())
+    info['max_uptime'] = int(sub_iter.next())
+    info['min_uptime'] = int(sub_iter.next())
+    info['last_crash'] = int(sub_iter.next())
+    info['last_start'] = int(sub_iter.next())
+    if prot_version > 1:
+        info['last_stop'] = int(sub_iter.next())
+    info['crash_avg1'] = sub_iter.next() == "1"
+    info['crash_avg10'] = float(sub_iter.next())
+    info['crash_avg30'] = float(sub_iter.next())
+
     return info
 
+
+def isempty(result):
+    """ raises an exception if the result is not empty"""
+    if result != "":
+        raise OperationalError(result)
+    else:
+        return True
+
+
 class Control:
     """
-    Use this module to manage your MonetDB databases. You can create, start, 
stop,
-    lock, unlock, destroy your databases and request status information.
+    Use this module to manage your MonetDB databases. You can create, start,
+    stop, lock, unlock, destroy your databases and request status information.
     """
     def __init__(self, hostname, port, passphrase):
         self.server = mapi.Connection()
-        self.server.connect(hostname, port, 'monetdb', passphrase, 
'merovingian', 'control')
+        self.hostname = hostname
+        self.port = port
+        self.passphrase = passphrase
+
+        # check connection
+        self.server.connect(hostname, port, 'monetdb', passphrase,
+                            'merovingian', 'control')
+        self.server.disconnect()
 
     def _send_command(self, database_name, command):
-        return self.server.cmd("%s %s\n" % (database_name, command))
+        self.server.connect(self.hostname, self.port, 'monetdb',
+                            self.passphrase, 'merovingian', 'control')
+        try:
+            return self.server.cmd("%s %s\n" % (database_name, command))
+        finally:
+            # always close connection
+            self.server.disconnect()
 
     def create(self, database_name):
         """
@@ -41,7 +85,7 @@ class Control:
         A database created with this command makes it available  for use,
         however in maintenance mode (see monetdb lock).
         """
-        return self._send_command(database_name, "create")
+        return isempty(self._send_command(database_name, "create"))
 
     def destroy(self, database_name):
         """
@@ -49,7 +93,7 @@ class Control:
         logfiles.  Once destroy has completed, all data is lost.
         Be careful when using this command.
         """
-        return self._send_command(database_name, "destroy")
+        return isempty(self._send_command(database_name, "destroy"))
 
     def lock(self, database_name):
         """
@@ -59,7 +103,7 @@ class Control:
         automatically.  Use the "release" command to bring
         the database back for normal usage.
         """
-        return self._send_command(database_name, "lock")
+        return isempty(self._send_command(database_name, "lock"))
 
     def release(self, database_name):
         """
@@ -67,7 +111,7 @@ class Control:
         database is available again for normal use.  Use the
         "lock" command to take a database under maintenance.
         """
-        return self._send_command(database_name, "release")
+        return isempty(self._send_command(database_name, "release"))
 
     def status(self, database_name=False):
         """
@@ -87,14 +131,14 @@ class Control:
         Starts the given database, if the MonetDB Database Server
         is running.
         """
-        return self._send_command(database_name, "start")
+        return isempty(self._send_command(database_name, "start"))
 
     def stop(self, database_name):
         """
         Stops the given database, if the MonetDB Database Server
         is running.
         """
-        return self._send_command(database_name, "stop")
+        return isempty(self._send_command(database_name, "stop"))
 
     def kill(self, database_name):
         """
@@ -103,14 +147,15 @@ class Control:
         as last resort to stop a database.  A database being
         killed may end up with data loss.
         """
-        return self._send_command(database_name, "kill")
+        return isempty(self._send_command(database_name, "kill"))
 
     def set(self, database_name, property_, value):
         """
         sets property to value for the given database
         for a list of properties, use `monetdb get all`
         """
-        return self._send_command(database_name, "%s=%s" % (property_, value))
+        return isempty(self._send_command(database_name, "%s=%s" % (property_,
+                                                                    value)))
 
     def get(self, database_name):
         """
@@ -132,7 +177,7 @@ class Control:
         unsets property, reverting to its inherited value from
         the default configuration for the given database
         """
-        return self._send_command(database_name, property_ + "=")
+        return isempty(self._send_command(database_name, property_ + "="))
 
     def rename(self, old, new):
         return self.set(old, "name", new)
diff --git a/clients/python2/monetdb/sql/converters.py 
b/clients/python2/monetdb/sql/converters.py
--- a/clients/python2/monetdb/sql/converters.py
+++ b/clients/python2/monetdb/sql/converters.py
@@ -50,4 +50,4 @@ class Monetizer:
     def convert(self, data):
         """
         """
-        return monetize.convert(data)
\ No newline at end of file
+        return monetize.convert(data)
diff --git a/clients/python2/monetdb/sql/cursors.py 
b/clients/python2/monetdb/sql/cursors.py
--- a/clients/python2/monetdb/sql/cursors.py
+++ b/clients/python2/monetdb/sql/cursors.py
@@ -380,133 +380,99 @@ class Cursor(object):
         if not block:
             block = ""
 
-        lines = block.split("\n")
-        firstline = lines[0]
+        for line in block.split("\n"):
+            if line.startswith(mapi.MSG_INFO):
+                logger.info(line[1:])
+                self.messages.append((Warning, line[1:]))
 
-        while firstline.startswith(mapi.MSG_INFO):
-            logger.info(firstline[1:])
-            self.messages.append((Warning, firstline[1:]))
-            lines = lines[1:]
-            firstline = lines[0]
+            elif line.startswith(mapi.MSG_QTABLE):
+                (self.__query_id, rowcount, columns, tuples) = line[2:].split()
 
-        if firstline.startswith(mapi.MSG_QTABLE):
-            (id, rowcount, columns, tuples) = firstline[2:].split()
-            columns = int(columns)   # number of columns in result
-            rowcount = int(rowcount) # total number of rows
-            tuples = int(tuples)     # number of rows in this set
-            rows = []
+                columns = int(columns)   # number of columns in result
+                self.rowcount = int(rowcount)  # total number of rows
+                tuples = int(tuples)     # number of rows in this set
+                self.__rows = []
 
-            # set up fields for description
-            table_name = [None]*columns
-            column_name = [None]*columns
-            type_ = [None]*columns
-            display_size = [None]*columns
-            internal_size = [None]*columns
-            precision = [None]*columns
-            scale = [None]*columns
-            null_ok = [None]*columns
+                # set up fields for description
+                table_name = [None] * columns
+                column_name = [None] * columns
+                type_ = [None] * columns
+                display_size = [None] * columns
+                internal_size = [None] * columns
+                precision = [None] * columns
+                scale = [None] * columns
+                null_ok = [None] * columns
+                typesizes = [(0, 0)] * columns
+                self.__offset = 0
+                self.lastrowid = None
 
-            typesizes = [(0,0)]*columns
+            elif line.startswith(mapi.MSG_HEADER):
+                (data, identity) = line[1:].split("#")
+                values = [x.strip() for x in data.split(",")]
+                identity = identity.strip()
 
-            for line in lines[1:]:
-                if line.startswith(mapi.MSG_HEADER):
-                    (data, identity) = line[1:].split("#")
-                    values = [x.strip() for x in data.split(",")]
-                    identity = identity.strip()
+                if identity == "table_name":
+                    table_name = values
+                elif identity == "name":
+                    column_name = values
+                elif identity == "type":
+                    type_ = values
+                elif identity == "length":
+                    length = values
+                elif identity == "typesizes":
+                    typesizes = [[int(j) for j in i.split()] for i in values]
+                    internal_size = [x[0] for x in typesizes]
+                    for num, typeelem in enumerate(type_):
+                        if typeelem in ['decimal']:
+                            precision[num] = typesizes[num][0]
+                            scale[num] = typesizes[num][1]
+                else:
+                    msg = "unknown header field"
+                    self.messages.append((InterfaceError, msg))
+                    self.__exception_handler(InterfaceError, msg)
 
-                    if identity == "table_name":
-                        table_name = values   # not used
-                    elif identity == "name":
-                        column_name = values
-                    elif identity == "type":
-                        type_ = values
-                    elif identity == "length":
-                        pass # not used
-                    elif identity == "typesizes":
-                        typesizes = [[int(j) for j in i.split()] for i in 
values]
-                        internal_size = [x[0] for x in typesizes]
-                        for num, typeelem in enumerate(type_):
-                            if typeelem in ['decimal']:
-                                precision[num] = typesizes[num][0]
-                                scale[num] = typesizes[num][1]
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to