How to use the apsw.complete function in apsw

To help you get started, we’ve selected a few apsw examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openaire / iis / iis-3rdparty-madis / src / main / resources / eu / dnetlib / iis / 3rdparty / scripts / madis / mexec.py View on Github external
if flowname == None:
        parser.print_help()
        sys.exit(1)

    try:
        f = open(flowname,'r')
    except Exception, e:
        exitwitherror("Error in opening SQL flow: " + str(e))


    statement = f.readline()
    if not statement:
        sys.exit()

    while True:
        while not apsw.complete(statement):
            line = f.readline()
            statement += line
            if not line:
                 if statement.rstrip('\r\n')!='':
                    sys.stderr.write("Incomplete query:"+statement)
                 f.close()
                 sys.exit()
        try :
            for row in Connection.cursor().execute(statement):
                if len(row) > 1:
                    print(json.dumps(row, separators=(',',':'), ensure_ascii=False).encode('utf_8', 'replace'))
                else:
                    print(unicode(row[0]).encode('utf_8', 'replace'))
            statement = ''
        except Exception, e:
            exitwitherror("Error when executing query: \n"+statement+"\nThe error was: "+ str(e))
github kovidgoyal / calibre / src / calibre / utils / apsw_shell.py View on Github external
For dot commands it will be one line.  For SQL statements it
        will be as many as is necessary to have a
        :meth:`~apsw.complete` statement (ie semicolon terminated).
        Returns None on end of file."""
        try:
            self._completion_first=True
            command=self.getline(self.prompt)
            if command is None:
                return None
            if len(command.strip())==0:
                return ""
            if command[0]=="?":
                command=".help "+command[1:]
            # incomplete SQL?
            while command[0]!="." and not apsw.complete(command):
                self._completion_first=False
                line=self.getline(self.moreprompt)
                if line is None:  # unexpected eof
                    raise self.Error("Incomplete SQL (line %d of %s): %s\n" % (self.input_line_number, getattr(self.stdin, "name", ""), command))
                if line in ("go", "/"):
                    break
                command=command+"\n"+line
            return command
        except KeyboardInterrupt:
            self.handle_interrupt()
            return ""
github plasticityai / magnitude / pymagnitude / third_party / _apsw / tools / shell.py View on Github external
"""Returns a complete input.

        For dot commands it will be one line.  For SQL statements it
        will be as many as is necessary to have a
        :meth:`~apsw.complete` statement (ie semicolon terminated).
        Returns None on end of file."""
        try:
            self._completion_first=True
            command=self.getline(self.prompt)
            if command is None:
                return None
            if len(command.strip())==0:
                return ""
            if command[0]=="?": command=".help "+command[1:]
            # incomplete SQL?
            while command[0]!="." and not apsw.complete(command):
                self._completion_first=False
                line=self.getline(self.moreprompt)
                if line is None: # unexpected eof
                    raise self.Error("Incomplete SQL (line %d of %s): %s\n" % (self.input_line_number, getattr(self.stdin, "name", ""), command))
                if line in ("go", "/"):
                    break
                command=command+"\n"+line
            return command
        except KeyboardInterrupt:
            self.handle_interrupt()
            return ""
github norbusan / calibre-debian / src / calibre / utils / apsw_shell.py View on Github external
For dot commands it will be one line.  For SQL statements it
        will be as many as is necessary to have a
        :meth:`~apsw.complete` statement (ie semicolon terminated).
        Returns None on end of file."""
        try:
            self._completion_first=True
            command=self.getline(self.prompt)
            if command is None:
                return None
            if len(command.strip())==0:
                return ""
            if command[0]=="?":
                command=".help "+command[1:]
            # incomplete SQL?
            while command[0]!="." and not apsw.complete(command):
                self._completion_first=False
                line=self.getline(self.moreprompt)
                if line is None:  # unexpected eof
                    raise self.Error("Incomplete SQL (line %d of %s): %s\n" % (self.input_line_number, getattr(self.stdin, "name", ""), command))
                if line in ("go", "/"):
                    break
                command=command+"\n"+line
            return command
        except KeyboardInterrupt:
            self.handle_interrupt()
            return ""
github openaire / iis / iis-3rdparty-madis / src / main / resources / eu / dnetlib / iis / 3rdparty / scripts / madis / mterm.py View on Github external
printterm("Automatic reload is now: " + str(automatic_reload))

        else:
            validcommand=False
            printterm("""unknown command. Enter ".help" for help""")

        if validcommand:
            histstatement='.'+command+' '+argument+rest
            try:
                readline.add_history(histstatement.encode('utf-8'))
            except:
                pass

    if statement:
        histstatement=statement
        while not apsw.complete(statement):
            more = raw_input_no_history('  ..> ')
            if more==None:
                statement=None
                break
            more=more.decode(output_encoding)
            statement = statement + '\n'.decode(output_encoding) + more
            histstatement=histstatement+' '+more

        reloadfunctions()
        number_of_kb_exceptions=0
        if not statement:
            printterm()
            continue
        try:
            if not validcommand:
                readline.add_history(histstatement.encode('utf-8'))