def __init__(self, username="******", password="******", hostname="localhost", port=50000, database="demo", autocommit=False, user=None, host=None): """ Set up a connection to a MonetDB SQL database. username -- username for connection (default: monetdb) password -- password for connection (default: monetdb) hostname -- hostname to connect to (default: localhost) port -- port to connect to (default: 50000) database -- name of the database (default: demo) autocommit -- enable/disable auto commit (default: False) """ if user is not None: username = user if host is not None: hostname = host self.mapi = mapi.Connection() self.mapi.connect(hostname=hostname, port=int(port), username=username, password=password, database=database, language="sql") self.set_autocommit(autocommit) self.set_sizeheader(True) self.set_replysize(100)
def __init__(self, hostname=None, port=50000, passphrase=None, unix_socket=None): 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 # check connection self.server.connect(hostname=hostname, port=port, username='******', password=passphrase, database='merovingian', language='control', unix_socket=unix_socket) self.server.disconnect()
def __init__(self, database, hostname=None, port=50000, username="******", password="******", unix_socket=None, autocommit=False, host=None, user=None): """ Set up a connection to a MonetDB SQL database. database -- name of the database hostname -- Hostname where monetDB is running port -- port to connect to (default: 50000) username -- username for connection (default: "monetdb") password -- password for connection (default: "monetdb") unix_socket -- socket to connect to. used when hostname not set (default: "/tmp/.s.monetdb.50000") autocommit -- enable/disable auto commit (default: False) """ # 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) self.set_autocommit(autocommit) self.set_sizeheader(True) self.set_replysize(100)
def __init__(self, hostname, port, passphrase): self.server = mapi.Connection() self.hostname = hostname self.port = port self.passphrase = passphrase # check connection self.server.connect(hostname, port, 'monetdb', passphrase, 'merovingian', 'control') self.server.disconnect()
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()