Python sqlite3 模块,Warning() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用sqlite3.Warning()

项目:PlasoScaffolder    作者:ClaudiaSaxer    | 项目源码 | 文件源码
def ExecuteQueryDetailed(
      self, query: str) -> sql_query_data.SQLQueryData:
    """Executes the SQL Query and gets detailed information.

    Args:
      query (str): The SQL Query to execute on the SQLite database.

    Returns:
      sql_query_data.SQLQueryData: The data to the Query
    """
    query_data = sql_query_data.SQLQueryData(
        data=None, has_error=True, columns=None)
    if not re.fullmatch('[A-Za-z,.;*=_0-9 ]*', query):
      query_data.error_message = ('Warning: Don\'t use any characters beside'
                                  ' a-z A-Z 0-9 . ; , * = _')
      return query_data

    if query.lower()[query.lower().find(' from '):].find(' as ') != -1:
      query_data.error_message = ('Warning: '
                                  'Don\'t use any alias for a table name')
      return query_data

    data_from_executed_query = self._ExecuteQuery(query, True)
    if not data_from_executed_query.has_error:
      duplicate_names = self._type_helper.GetDuplicateColumnNames(
          data_from_executed_query.columns)
      if duplicate_names:
        duplicate_names_as_string = ' '.join(duplicate_names)
        data_from_executed_query.has_error = True
        data_from_executed_query.error_message = (
            'Please use an alias (AS) for '
            'those column names: {0}'.format(duplicate_names_as_string))
      if not data_from_executed_query.has_error:

        data_from_executed_query.columns = (
            self._type_helper.AddMissingTypesFromSchema(
                data_from_executed_query.columns, query))

    return data_from_executed_query
项目:PlasoScaffolder    作者:ClaudiaSaxer    | 项目源码 | 文件源码
def _ExecuteQuery(
      self, query: str, detailed: bool=True) -> sql_query_data.SQLQueryData:
    """Executes the SQL Query.

    Args:
      query (str): The SQL Query to execute on the SQLite database.
      detailed (bool): True if additional information about the query is needed

    Returns:
      sql_query_data.SQLQueryData: The data to the Query
    """
    query_data = sql_query_data.SQLQueryData()
    try:
      with self._connection:
        self._connection.execute('BEGIN')
        cursor = self._connection.execute(query)
        query_data.data = cursor.fetchall()
        if detailed:
          query_data.columns = (
              self._type_helper.GetColumnInformationFromDescription(
                  cursor.description))
        self._connection.execute('ROLLBACK')
    except sqlite3.Error as error:
      query_data.error_message = 'Error: {0}'.format(str(error))
      query_data.has_error = True
    except sqlite3.Warning as warning:
      query_data.error_message = 'Warning: {0}'.format(str(warning))
      query_data.has_error = True

    return query_data
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def CheckConnectionCall(self):
        """
        Call a connection with a non-string SQL request: check error handling
        of the statement constructor.
        """
        self.assertRaises(sqlite.Warning, self.con, 1)
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def CheckWarning(self):
        self.assertTrue(issubclass(sqlite.Warning, StandardError),
                        "Warning is not a subclass of StandardError")
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def CheckExceptions(self):
        # Optional DB-API extension.
        self.assertEqual(self.cx.Warning, sqlite.Warning)
        self.assertEqual(self.cx.Error, sqlite.Error)
        self.assertEqual(self.cx.InterfaceError, sqlite.InterfaceError)
        self.assertEqual(self.cx.DatabaseError, sqlite.DatabaseError)
        self.assertEqual(self.cx.DataError, sqlite.DataError)
        self.assertEqual(self.cx.OperationalError, sqlite.OperationalError)
        self.assertEqual(self.cx.IntegrityError, sqlite.IntegrityError)
        self.assertEqual(self.cx.InternalError, sqlite.InternalError)
        self.assertEqual(self.cx.ProgrammingError, sqlite.ProgrammingError)
        self.assertEqual(self.cx.NotSupportedError, sqlite.NotSupportedError)
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def CheckExecuteTooMuchSql(self):
        try:
            self.cu.execute("select 5+4; select 4+5")
            self.fail("should have raised a Warning")
        except sqlite.Warning:
            return
        except:
            self.fail("raised wrong exception")
项目:vsphere-storage-for-docker    作者:vmware    | 项目源码 | 文件源码
def CheckConnectionCall(self):
        """
        Call a connection with a non-string SQL request: check error handling
        of the statement constructor.
        """
        self.assertRaises(sqlite.Warning, self.con, 1)
项目:vsphere-storage-for-docker    作者:vmware    | 项目源码 | 文件源码
def CheckWarning(self):
        self.assertTrue(issubclass(sqlite.Warning, StandardError),
                        "Warning is not a subclass of StandardError")
项目:vsphere-storage-for-docker    作者:vmware    | 项目源码 | 文件源码
def CheckExceptions(self):
        # Optional DB-API extension.
        self.assertEqual(self.cx.Warning, sqlite.Warning)
        self.assertEqual(self.cx.Error, sqlite.Error)
        self.assertEqual(self.cx.InterfaceError, sqlite.InterfaceError)
        self.assertEqual(self.cx.DatabaseError, sqlite.DatabaseError)
        self.assertEqual(self.cx.DataError, sqlite.DataError)
        self.assertEqual(self.cx.OperationalError, sqlite.OperationalError)
        self.assertEqual(self.cx.IntegrityError, sqlite.IntegrityError)
        self.assertEqual(self.cx.InternalError, sqlite.InternalError)
        self.assertEqual(self.cx.ProgrammingError, sqlite.ProgrammingError)
        self.assertEqual(self.cx.NotSupportedError, sqlite.NotSupportedError)
项目:vsphere-storage-for-docker    作者:vmware    | 项目源码 | 文件源码
def CheckExecuteTooMuchSql(self):
        try:
            self.cu.execute("select 5+4; select 4+5")
            self.fail("should have raised a Warning")
        except sqlite.Warning:
            return
        except:
            self.fail("raised wrong exception")
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def CheckConnectionCall(self):
        """
        Call a connection with a non-string SQL request: check error handling
        of the statement constructor.
        """
        self.assertRaises(sqlite.Warning, self.con, 1)
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def CheckWarning(self):
        self.assertTrue(issubclass(sqlite.Warning, StandardError),
                        "Warning is not a subclass of StandardError")
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def CheckExceptions(self):
        # Optional DB-API extension.
        self.assertEqual(self.cx.Warning, sqlite.Warning)
        self.assertEqual(self.cx.Error, sqlite.Error)
        self.assertEqual(self.cx.InterfaceError, sqlite.InterfaceError)
        self.assertEqual(self.cx.DatabaseError, sqlite.DatabaseError)
        self.assertEqual(self.cx.DataError, sqlite.DataError)
        self.assertEqual(self.cx.OperationalError, sqlite.OperationalError)
        self.assertEqual(self.cx.IntegrityError, sqlite.IntegrityError)
        self.assertEqual(self.cx.InternalError, sqlite.InternalError)
        self.assertEqual(self.cx.ProgrammingError, sqlite.ProgrammingError)
        self.assertEqual(self.cx.NotSupportedError, sqlite.NotSupportedError)
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def CheckExecuteTooMuchSql(self):
        try:
            self.cu.execute("select 5+4; select 4+5")
            self.fail("should have raised a Warning")
        except sqlite.Warning:
            return
        except:
            self.fail("raised wrong exception")
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def CheckConnectionCall(self):
        """
        Call a connection with a non-string SQL request: check error handling
        of the statement constructor.
        """
        self.assertRaises(sqlite.Warning, self.con, 1)
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def CheckWarning(self):
        self.assertTrue(issubclass(sqlite.Warning, StandardError),
                        "Warning is not a subclass of StandardError")
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def CheckExceptions(self):
        # Optional DB-API extension.
        self.assertEqual(self.cx.Warning, sqlite.Warning)
        self.assertEqual(self.cx.Error, sqlite.Error)
        self.assertEqual(self.cx.InterfaceError, sqlite.InterfaceError)
        self.assertEqual(self.cx.DatabaseError, sqlite.DatabaseError)
        self.assertEqual(self.cx.DataError, sqlite.DataError)
        self.assertEqual(self.cx.OperationalError, sqlite.OperationalError)
        self.assertEqual(self.cx.IntegrityError, sqlite.IntegrityError)
        self.assertEqual(self.cx.InternalError, sqlite.InternalError)
        self.assertEqual(self.cx.ProgrammingError, sqlite.ProgrammingError)
        self.assertEqual(self.cx.NotSupportedError, sqlite.NotSupportedError)
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def CheckExecuteTooMuchSql(self):
        try:
            self.cu.execute("select 5+4; select 4+5")
            self.fail("should have raised a Warning")
        except sqlite.Warning:
            return
        except:
            self.fail("raised wrong exception")
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def CheckConnectionCall(self):
        """
        Call a connection with a non-string SQL request: check error handling
        of the statement constructor.
        """
        self.assertRaises(sqlite.Warning, self.con, 1)
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def CheckWarning(self):
        self.assertTrue(issubclass(sqlite.Warning, Exception),
                     "Warning is not a subclass of Exception")
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def CheckExceptions(self):
        # Optional DB-API extension.
        self.assertEqual(self.cx.Warning, sqlite.Warning)
        self.assertEqual(self.cx.Error, sqlite.Error)
        self.assertEqual(self.cx.InterfaceError, sqlite.InterfaceError)
        self.assertEqual(self.cx.DatabaseError, sqlite.DatabaseError)
        self.assertEqual(self.cx.DataError, sqlite.DataError)
        self.assertEqual(self.cx.OperationalError, sqlite.OperationalError)
        self.assertEqual(self.cx.IntegrityError, sqlite.IntegrityError)
        self.assertEqual(self.cx.InternalError, sqlite.InternalError)
        self.assertEqual(self.cx.ProgrammingError, sqlite.ProgrammingError)
        self.assertEqual(self.cx.NotSupportedError, sqlite.NotSupportedError)
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def CheckExecuteTooMuchSql(self):
        try:
            self.cu.execute("select 5+4; select 4+5")
            self.fail("should have raised a Warning")
        except sqlite.Warning:
            return
        except:
            self.fail("raised wrong exception")
项目:knowledge-management    作者:dgore7    | 项目源码 | 文件源码
def register(self, username, pword, sec_question, sec_answer):
        """
        Attempts to enter a new username and pword into the USERS table

        :param username: new username, MUST BE UNIQUE
        :param pword: new password

        :return: False if username is not unique (can't have duplicate usernames)
                 True if username is unique and user is put in db
        """
        self.lock.acquire()
        result = 0
        c = self.conn.cursor()
        try:
            c.execute("INSERT INTO GROUPS(groupname, user_created) VALUES(?,?)", (username + "_personal_repo", False))
            gid = c.lastrowid
            print(type(gid))
            c.execute("INSERT INTO USER(username, password, question, answer, repo_id) VALUES(?,?,?,?,?)", (username, pword, sec_question,
                                                                                            sec_answer,gid))
            c.execute("INSERT INTO USER_GROUP(group_id, username) VALUES(?,?)", (gid, username))
            self.conn.commit()
            result = gid
        # username is not unique
        except sqlite3.Warning:
            print('ignored')
        except Exception as e:
            print('Exception in register:', e)
        finally:
            self.lock.release()
        return result
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def CheckConnectionCall(self):
        """
        Call a connection with a non-string SQL request: check error handling
        of the statement constructor.
        """
        self.assertRaises(sqlite.Warning, self.con, 1)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def CheckWarning(self):
        self.assertTrue(issubclass(sqlite.Warning, StandardError),
                        "Warning is not a subclass of StandardError")
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def CheckExceptions(self):
        # Optional DB-API extension.
        self.assertEqual(self.cx.Warning, sqlite.Warning)
        self.assertEqual(self.cx.Error, sqlite.Error)
        self.assertEqual(self.cx.InterfaceError, sqlite.InterfaceError)
        self.assertEqual(self.cx.DatabaseError, sqlite.DatabaseError)
        self.assertEqual(self.cx.DataError, sqlite.DataError)
        self.assertEqual(self.cx.OperationalError, sqlite.OperationalError)
        self.assertEqual(self.cx.IntegrityError, sqlite.IntegrityError)
        self.assertEqual(self.cx.InternalError, sqlite.InternalError)
        self.assertEqual(self.cx.ProgrammingError, sqlite.ProgrammingError)
        self.assertEqual(self.cx.NotSupportedError, sqlite.NotSupportedError)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def CheckExecuteTooMuchSql(self):
        try:
            self.cu.execute("select 5+4; select 4+5")
            self.fail("should have raised a Warning")
        except sqlite.Warning:
            return
        except:
            self.fail("raised wrong exception")
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def CheckConnectionCall(self):
        """
        Call a connection with a non-string SQL request: check error handling
        of the statement constructor.
        """
        self.assertRaises(sqlite.Warning, self.con, 1)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def CheckWarning(self):
        self.assertTrue(issubclass(sqlite.Warning, StandardError),
                        "Warning is not a subclass of StandardError")
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def CheckExceptions(self):
        # Optional DB-API extension.
        self.assertEqual(self.cx.Warning, sqlite.Warning)
        self.assertEqual(self.cx.Error, sqlite.Error)
        self.assertEqual(self.cx.InterfaceError, sqlite.InterfaceError)
        self.assertEqual(self.cx.DatabaseError, sqlite.DatabaseError)
        self.assertEqual(self.cx.DataError, sqlite.DataError)
        self.assertEqual(self.cx.OperationalError, sqlite.OperationalError)
        self.assertEqual(self.cx.IntegrityError, sqlite.IntegrityError)
        self.assertEqual(self.cx.InternalError, sqlite.InternalError)
        self.assertEqual(self.cx.ProgrammingError, sqlite.ProgrammingError)
        self.assertEqual(self.cx.NotSupportedError, sqlite.NotSupportedError)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def CheckExecuteTooMuchSql(self):
        try:
            self.cu.execute("select 5+4; select 4+5")
            self.fail("should have raised a Warning")
        except sqlite.Warning:
            return
        except:
            self.fail("raised wrong exception")
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def CheckConnectionCall(self):
        """
        Call a connection with a non-string SQL request: check error handling
        of the statement constructor.
        """
        self.assertRaises(sqlite.Warning, self.con, 1)
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def CheckWarning(self):
        self.assertTrue(issubclass(sqlite.Warning, StandardError),
                        "Warning is not a subclass of StandardError")
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def CheckExceptions(self):
        # Optional DB-API extension.
        self.assertEqual(self.cx.Warning, sqlite.Warning)
        self.assertEqual(self.cx.Error, sqlite.Error)
        self.assertEqual(self.cx.InterfaceError, sqlite.InterfaceError)
        self.assertEqual(self.cx.DatabaseError, sqlite.DatabaseError)
        self.assertEqual(self.cx.DataError, sqlite.DataError)
        self.assertEqual(self.cx.OperationalError, sqlite.OperationalError)
        self.assertEqual(self.cx.IntegrityError, sqlite.IntegrityError)
        self.assertEqual(self.cx.InternalError, sqlite.InternalError)
        self.assertEqual(self.cx.ProgrammingError, sqlite.ProgrammingError)
        self.assertEqual(self.cx.NotSupportedError, sqlite.NotSupportedError)
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def CheckExecuteTooMuchSql(self):
        try:
            self.cu.execute("select 5+4; select 4+5")
            self.fail("should have raised a Warning")
        except sqlite.Warning:
            return
        except:
            self.fail("raised wrong exception")
项目:challenges    作者:dwyde    | 项目源码 | 文件源码
def _run_query(self, query_string):
        """ Run a query.
        """
        cursor = self.conn.cursor()
        try:
            cursor.execute(query_string)
        except (sqlite3.OperationalError, sqlite3.Warning):
            pass
        results = cursor.fetchall()
        cursor.close()
        return results
项目:challenges    作者:dwyde    | 项目源码 | 文件源码
def _run_query(self, query_string, *parameters):
        """ Run a query.
        """
        cursor = self.conn.cursor()
        try:
            cursor.execute(query_string, parameters)
        except (sqlite3.OperationalError, sqlite3.Warning):
            pass
        results = cursor.fetchall()
        cursor.close()
        return results
项目:csc376-interview-portal    作者:cormac-obrien    | 项目源码 | 文件源码
def register(self, username, password, authkey):
        self.lock.acquire()
        created = False
        c = self.conn.cursor()
        try:
            c.execute("INSERT INTO Login(username, password, authkey) VALUES(?,?,?)", (username, password, authkey))
            self.conn.commit()
            created = True
        except sqlite3.Warning:
            print('unsucessful')
        except Exception as e:
            print('Exception in register:', e)
        finally:
            self.lock.release()
            return created
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def CheckConnectionCall(self):
        """
        Call a connection with a non-string SQL request: check error handling
        of the statement constructor.
        """
        self.assertRaises(sqlite.Warning, self.con, 1)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def CheckWarning(self):
        self.assertTrue(issubclass(sqlite.Warning, Exception),
                     "Warning is not a subclass of Exception")
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def CheckExceptions(self):
        # Optional DB-API extension.
        self.assertEqual(self.cx.Warning, sqlite.Warning)
        self.assertEqual(self.cx.Error, sqlite.Error)
        self.assertEqual(self.cx.InterfaceError, sqlite.InterfaceError)
        self.assertEqual(self.cx.DatabaseError, sqlite.DatabaseError)
        self.assertEqual(self.cx.DataError, sqlite.DataError)
        self.assertEqual(self.cx.OperationalError, sqlite.OperationalError)
        self.assertEqual(self.cx.IntegrityError, sqlite.IntegrityError)
        self.assertEqual(self.cx.InternalError, sqlite.InternalError)
        self.assertEqual(self.cx.ProgrammingError, sqlite.ProgrammingError)
        self.assertEqual(self.cx.NotSupportedError, sqlite.NotSupportedError)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def CheckExecuteTooMuchSql(self):
        try:
            self.cu.execute("select 5+4; select 4+5")
            self.fail("should have raised a Warning")
        except sqlite.Warning:
            return
        except:
            self.fail("raised wrong exception")
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def CheckConnectionCall(self):
        """
        Call a connection with a non-string SQL request: check error handling
        of the statement constructor.
        """
        self.assertRaises(sqlite.Warning, self.con, 1)
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def CheckWarning(self):
        self.assertTrue(issubclass(sqlite.Warning, StandardError),
                        "Warning is not a subclass of StandardError")
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def CheckExceptions(self):
        # Optional DB-API extension.
        self.assertEqual(self.cx.Warning, sqlite.Warning)
        self.assertEqual(self.cx.Error, sqlite.Error)
        self.assertEqual(self.cx.InterfaceError, sqlite.InterfaceError)
        self.assertEqual(self.cx.DatabaseError, sqlite.DatabaseError)
        self.assertEqual(self.cx.DataError, sqlite.DataError)
        self.assertEqual(self.cx.OperationalError, sqlite.OperationalError)
        self.assertEqual(self.cx.IntegrityError, sqlite.IntegrityError)
        self.assertEqual(self.cx.InternalError, sqlite.InternalError)
        self.assertEqual(self.cx.ProgrammingError, sqlite.ProgrammingError)
        self.assertEqual(self.cx.NotSupportedError, sqlite.NotSupportedError)
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def CheckExecuteTooMuchSql(self):
        try:
            self.cu.execute("select 5+4; select 4+5")
            self.fail("should have raised a Warning")
        except sqlite.Warning:
            return
        except:
            self.fail("raised wrong exception")
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def CheckConnectionCall(self):
        """
        Call a connection with a non-string SQL request: check error handling
        of the statement constructor.
        """
        self.assertRaises(sqlite.Warning, self.con, 1)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def CheckWarning(self):
        self.assertTrue(issubclass(sqlite.Warning, Exception),
                     "Warning is not a subclass of Exception")
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def CheckExceptions(self):
        # Optional DB-API extension.
        self.assertEqual(self.cx.Warning, sqlite.Warning)
        self.assertEqual(self.cx.Error, sqlite.Error)
        self.assertEqual(self.cx.InterfaceError, sqlite.InterfaceError)
        self.assertEqual(self.cx.DatabaseError, sqlite.DatabaseError)
        self.assertEqual(self.cx.DataError, sqlite.DataError)
        self.assertEqual(self.cx.OperationalError, sqlite.OperationalError)
        self.assertEqual(self.cx.IntegrityError, sqlite.IntegrityError)
        self.assertEqual(self.cx.InternalError, sqlite.InternalError)
        self.assertEqual(self.cx.ProgrammingError, sqlite.ProgrammingError)
        self.assertEqual(self.cx.NotSupportedError, sqlite.NotSupportedError)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def CheckExecuteTooMuchSql(self):
        try:
            self.cu.execute("select 5+4; select 4+5")
            self.fail("should have raised a Warning")
        except sqlite.Warning:
            return
        except:
            self.fail("raised wrong exception")