コード例 #1
0
 def add_connection(self, conn_id, username='******', password='******'):
     if self.conn_map.get(conn_id, None) is None:
         hostname = self.hostname
         port = self.port
         database = self.database
         language = self.language
         if language == 'sql':
             dbh = pymonetdb.connect(username=username,
                                     password=password,
                                     hostname=hostname,
                                     port=port,
                                     database=database,
                                     autocommit=True)
             crs = dbh.cursor()
         else:
             dbh = malmapi.Connection()
             dbh.connect(database=database,
                         username=username,
                         password=password,
                         language=language,
                         hostname=hostname,
                         port=port)
             crs = MapiCursor(dbh)
         conn = SQLLogicConnection(conn_id,
                                   dbh=dbh,
                                   crs=crs,
                                   language=language)
         self.conn_map[conn_id] = conn
         return conn
コード例 #2
0
 def connect(self,
             username='******',
             password='******',
             hostname='localhost',
             port=None,
             database='demo',
             language='sql',
             timeout=None):
     self.language = language
     self.hostname = hostname
     self.port = port
     self.database = database
     self.timeout = timeout
     if language == 'sql':
         self.dbh = pymonetdb.connect(username=username,
                                      password=password,
                                      hostname=hostname,
                                      port=port,
                                      database=database,
                                      autocommit=True)
         self.dbh.set_uploader(transfer_handler)
         self.dbh.set_downloader(transfer_handler)
         self.crs = self.dbh.cursor()
     else:
         dbh = malmapi.Connection()
         dbh.connect(database=database,
                     username=username,
                     password=password,
                     language=language,
                     hostname=hostname,
                     port=port)
         self.crs = MapiCursor(dbh)
コード例 #3
0
 def connect(self,
             username='******',
             password='******',
             hostname='localhost',
             port=None,
             database='demo',
             language='sql'):
     self.language = language
     self.hostname = hostname
     self.port = port
     self.database = database
     if language == 'sql':
         self.dbh = pymonetdb.connect(username=username,
                                      password=password,
                                      hostname=hostname,
                                      port=port,
                                      database=database,
                                      autocommit=True)
         self.crs = self.dbh.cursor()
     else:
         dbh = malmapi.Connection()
         dbh.connect(database=database,
                     username=username,
                     password=password,
                     language=language,
                     hostname=hostname,
                     port=port)
         self.crs = MapiCursor(dbh)
コード例 #4
0
def main():
    parser = argparse.ArgumentParser(description='Create a Sqllogictest')
    parser.add_argument('--host',
                        action='store',
                        default='localhost',
                        help='hostname where the server runs')
    parser.add_argument('--port',
                        action='store',
                        type=int,
                        default=50000,
                        help='port the server listens on')
    parser.add_argument('--database',
                        action='store',
                        default='demo',
                        help='name of the database')
    parser.add_argument('--user',
                        action='store',
                        default='monetdb',
                        help='user')
    parser.add_argument('--password',
                        action='store',
                        default='monetdb',
                        help='password')
    parser.add_argument('--language',
                        action='store',
                        default='sql',
                        help='language to connect to the database')
    parser.add_argument('--sort',
                        action='store',
                        default='rowsort',
                        choices=['nosort', 'rowsort', 'valuesort'],
                        help='how to sort the values')
    parser.add_argument('--hashlimit',
                        action='store',
                        type=int,
                        default=100,
                        help='hash limit')
    parser.add_argument('--results',
                        action='store',
                        type=argparse.FileType('w'),
                        help='file to store results of queries')
    global opts
    opts = parser.parse_args()

    global dbh
    global crs
    if opts.language == 'sql':
        dbh = pymonetdb.connect(username=opts.user,
                                password=opts.password,
                                hostname=opts.host,
                                port=opts.port,
                                database=opts.database,
                                autocommit=True)
        crs = dbh.cursor()
    else:
        dbh = malmapi.Connection()
        dbh.connect(database=opts.database,
                    username=opts.user,
                    password=opts.password,
                    language='mal',
                    hostname=opts.host,
                    port=opts.port)
        crs = MapiCursor(dbh)

    query = []
    incomment = False
    incopy = False
    while True:
        line = sys.stdin.readline()
        if not line:
            break
        if incomment:
            if '*/' in line:
                line = line[line.find('*/') + 2:]
                incomment = False
            else:
                continue
        line = re.sub('/\*.*?\*/', ' ', line)
        if '/*' in line:
            line = line[:line.find('/*')]
            incomment = True
        line = line.rstrip()
        if not line:
            continue
        if not query:
            res = re.match('[^\'"]*((\'[^\']*\'|"[^"]*")[^\'"]*)*#', line)
            if res is not None:
                line = res.group(0)[:-1].rstrip()
            res = re.match('[^\'"]*((\'[^\']*\'|"[^"]*")[^\'"]*)*--', line)
            if res is not None:
                line = res.group(0)[:-2].rstrip()
            if not line:
                continue
        if is_complete_stmt(query, line):
            if opts.language == 'sql':
                l = line.rstrip(';')
            else:
                l = line
            query.append(l)
            data = None
            stmt = '\n'.join(query)
            if is_copyfrom_stmt('\n'.join(query)):
                data = []
                while True:
                    line = sys.stdin.readline()
                    if not line or line == '\n':
                        break
                    data.append(line.rstrip('\n'))
            to_sqllogic_test(stmt, data)
            query = []
        else:
            query.append(line)