Esempio n. 1
0
def initialize(args):
    server = mapi.Connection()
    server.connect(hostname="127.0.0.1",
                   port=50000,
                   username="******",
                   password="******",
                   database=args[1],
                   language="sql")

    global_node.append(server)
    global_node.append(args[1])
    global_node.append(
        pymonetdb.connect(username="******",
                          password="******",
                          port=50000,
                          hostname="127.0.0.1",
                          database=args[1]))

    for db in args[2:]:
        server = mapi.Connection()
        server.connect(hostname="127.0.0.1",
                       port=50000,
                       username="******",
                       password="******",
                       database=db,
                       language="sql")
        local_nodes.append((server, db))
Esempio n. 2
0
    def __init__(self,
                 hostname=None,
                 port=50000,
                 passphrase=None,
                 unix_socket=None,
                 connect_timeout=-1):

        if not unix_socket:
            unix_socket = "/tmp/.s.merovingian.%i" % port

        if platform.system() == "Windows" and not hostname:
            hostname = "localhost"

        self.server = mapi.Connection()
        self.hostname = hostname
        self.port = port
        self.passphrase = passphrase
        self.unix_socket = unix_socket
        self.connect_timeout = connect_timeout

        # check connection
        self.server.connect(hostname=hostname,
                            port=port,
                            username='******',
                            password=passphrase,
                            database='merovingian',
                            language='control',
                            unix_socket=unix_socket,
                            connect_timeout=connect_timeout)
        self.server.disconnect()
Esempio n. 3
0
    async def acquire(self):  #### get connection objects
        db_conn = {}
        db_conn['local'] = []
        db_conn['global'] = {}

        await self._reload()

        conn = await self.db_objects['global']['pool'].acquire()

        db_conn['global'][
            'async_con'] = conn  ## global asynchronous connection object - this is used to execute commands on the remote database
        db_conn['global']['dbname'] = self.db_objects['global'][
            'dbname']  ## global database name - required by remote tables to connect to the remote database

        glob = urlparse(self.db_objects['global']['dbname'])
        server = mapi.Connection()
        server.connect(hostname=glob.hostname,
                       port=glob.port,
                       username="******",
                       password="******",
                       database=glob.path[1:],
                       language="sql")

        db_conn['global'][
            'con'] = server  ## global blocking connection objects - required at this time because monetdb does not support create commands concurrently

        for db_object in self.db_objects['local']:
            loc = urlparse(db_object['dbname'])
            conn = await db_object['pool'].acquire()
            server2 = mapi.Connection()
            server2.connect(hostname=loc.hostname,
                            port=loc.port,
                            username="******",
                            password="******",
                            database=loc.path[1:],
                            language="sql")

            local_node = {}
            local_node['async_con'] = conn
            local_node['dbname'] = db_object['dbname']
            local_node['con'] = server2
            db_conn['local'].append(
                local_node
            )  # for each local node an asynchronous connection object, the database name, and a blocking connection object
        return db_conn
Esempio n. 4
0
    def __init__(self,
                 database,
                 hostname=None,
                 port=50000,
                 username="******",
                 password="******",
                 unix_socket=None,
                 autocommit=False,
                 host=None,
                 user=None,
                 connect_timeout=-1):
        """ Set up a connection to a MonetDB SQL database.

        args:
            database (str): name of the database
            hostname (str): Hostname where monetDB is running
            port (int): port to connect to (default: 50000)
            username (str): username for connection (default: "monetdb")
            password (str): password for connection (default: "monetdb")
            unix_socket (str): socket to connect to. used when hostname not set
                                (default: "/tmp/.s.monetdb.50000")
            autocommit (bool):  enable/disable auto commit (default: False)
            connect_timeout -- the socket timeout while connecting
                               (default: see python socket module)

        returns:
            Connection object

        """

        # The DB API spec is not specific about this
        if host:
            hostname = host
        if user:
            username = user

        if platform.system() == "Windows" and not hostname:
            hostname = "localhost"

        self.mapi = mapi.Connection()
        self.mapi.connect(hostname=hostname,
                          port=int(port),
                          username=username,
                          password=password,
                          database=database,
                          language="sql",
                          unix_socket=unix_socket,
                          connect_timeout=connect_timeout)
        self.set_autocommit(autocommit)
        self.set_sizeheader(True)

        self.set_replysize(100)

        self.autocommit = autocommit
        self.sizeheader = True
        self.replysize = None
Esempio n. 5
0
 def __init__(self):
     self._mapi = mapi.Connection()
     self._heartbeat = 0
     self._buffer = ""
     self._objects = list()
Esempio n. 6
0
COMMIT;
"""

doesnotwork = """-- some comment
START TRANSACTION;
CREATE TABLE b(i integer);
COPY 1 RECORDS INTO b FROM STDIN USING DELIMITERS ',','\\n','"';
42
CREATE TABLE c(i integer);
COPY 2 RECORDS INTO c FROM STDIN USING DELIMITERS ',','\\n','"';
42
84
COMMIT;
"""

cn = mapi.Connection()

open(cn)
print(cn.cmd('s' + works + ';\n'))
cn.disconnect()

open(cn)
print(cn.cmd('s' + doesnotwork + ';\n'))
cn.disconnect()

# this should show a-e, but only shows a
open(cn)
print(cn.cmd('sSELECT name FROM tables WHERE system=0;\n'))
print(cn.cmd('sDROP TABLE a;\n'))

cn.disconnect()