Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
desc="""Use this program to run madSQL queries on data coming from standard input. You may provide a database to run your queries. Results are streamed to standard output.
"""
parser = OptionParser(description=desc, usage="usage: %prog [options] [dbname] flowname",
version="%prog 1.0")
parser.add_option("-f", "--flow",
help="flow file to execute")
parser.add_option("-d", "--db",
help="db to connect")
parser.add_option("-w", "--dbw",
help="db to connect (open in create mode)")
(options, args) = parser.parse_args()
dbname = ''
flags = apsw.SQLITE_OPEN_READWRITE | apsw.SQLITE_OPEN_CREATE
try:
dbname = args[0]
flags = apsw.SQLITE_OPEN_READWRITE
except:
pass
if options.db != None:
dbname = options.db
flags = apsw.SQLITE_OPEN_READWRITE
if options.dbw != None:
dbname = options.dbw
try:
Connection=madis.functions.Connection(dbname, flags)
def open(self):
self.db = apsw.Connection(
self._db_path,
flags=(
apsw.SQLITE_OPEN_READWRITE |
apsw.SQLITE_OPEN_CREATE |
apsw.SQLITE_OPEN_URI
)
)
def exec_factory(cursor, statement, bindings):
tpl = namedtuple('row', (d[0] for d in cursor.getdescription()))
cursor.setrowtrace(lambda cursor, row: tpl(*row))
return True
self.db.setexectrace(exec_factory)
self.execute(self.PRAGMAS)
self.execute(self.CREATE_TABLES_QUERY)
register_canonical_functions(self.db)
register_trending_functions(self.db)
version="%prog 1.0")
parser.add_option("-f", "--flow",
help="flow file to execute")
parser.add_option("-d", "--db",
help="db to connect")
parser.add_option("-w", "--dbw",
help="db to connect (open in create mode)")
(options, args) = parser.parse_args()
dbname = ''
flags = apsw.SQLITE_OPEN_READWRITE | apsw.SQLITE_OPEN_CREATE
try:
dbname = args[0]
flags = apsw.SQLITE_OPEN_READWRITE
except:
pass
if options.db != None:
dbname = options.db
flags = apsw.SQLITE_OPEN_READWRITE
if options.dbw != None:
dbname = options.dbw
try:
Connection=madis.functions.Connection(dbname, flags)
except Exception, e:
exitwitherror("Error in opening DB: " + str(dbname) + "\nThe error was: " + str(e))