How to use the apsw.SQLError 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 probcomp / bayeslite / tests / test_sessions.py View on Github external
def _nonexistent_table_helper(executor, tr):
    query = 'SELECT * FROM nonexistent_table'
    try:
        executor(query)
        assert False
    except apsw.SQLError:
        #tr._start_new_session()
        assert tr._check_error_entries(tr.session_id) > 0
github rvianello / chemicalite / test / molecule.py View on Github external
def test_cast_to_qmol(self):
        c = self.db.cursor()        
        c.execute("select qmol('CCC')")
        c.execute("select qmol('C[*]C')")
        c.execute("select qmol('[C,N]')")
        self.assertRaises(apsw.SQLError,lambda : c.execute("select qmol('BAD')"))
github probcomp / bdbcontrib / tests / test_parallel.py View on Github external
bdb.execute('ANALYZE t_cc MODELS 0-2 FOR 10 ITERATIONS WAIT')

        # How to properly use the estimate_pairwise_similarity function.
        parallel.estimate_pairwise_similarity(
            bdb_file.name, 't', 't_cc'
        )

        # Should complain with bad core value
        with pytest.raises(BLE):
            parallel.estimate_pairwise_similarity(
                bdb_file.name, 't', 't_cc', cores=0
            )

        # Should complain if overwrite flag is not set, but t_similarity
        # exists
        with pytest.raises(SQLError):
            parallel.estimate_pairwise_similarity(
                bdb_file.name, 't', 't_cc'
            )
        # Should complain if model and table don't exist
        with pytest.raises(SQLError):
            parallel.estimate_pairwise_similarity(
                bdb_file.name, 'foo', 'foo_cc'
            )
        # Should complain if bdb_file doesn't exist
        with tempfile.NamedTemporaryFile() as does_not_exist:
            with pytest.raises(SQLError):
                parallel.estimate_pairwise_similarity(
                    does_not_exist.name, 't', 't_cc'
                )

        # Should run fine if overwrite flag is set
github kovidgoyal / calibre / src / calibre / utils / apsw_shell.py View on Github external
master="sqlite_temp_master"
                else:
                    master="[%s].sqlite_master" % (db,)
                for row in cur.execute("select * from "+master).fetchall():
                    for col in (1,2):
                        if row[col] not in other and not row[col].startswith("sqlite_"):
                            other.append(row[col])
                    if row[0]=="table":
                        try:
                            for table in cur.execute("pragma [%s].table_info([%s])" % (db, row[1],)).fetchall():
                                if table[1] not in other:
                                    other.append(table[1])
                                for item in table[2].split():
                                    if item not in other:
                                        other.append(item)
                        except apsw.SQLError:
                            # See https://code.google.com/p/apsw/issues/detail?id=86
                            pass

            self._completion_cache=[self._sqlite_keywords, self._sqlite_functions, self._sqlite_special_names, collations, databases, other]
            for i in range(len(self._completion_cache)):
                self._completion_cache[i].sort()

        # be somewhat sensible about pragmas
        if "pragma " in line.lower():
            t=self._get_prev_tokens(line.lower(), end)

            # pragma foo = bar
            if len(t)>2 and t[-3]=="pragma":
                # t[-2] should be a valid one
                for p in self._pragmas:
                    if p.replace("=","")==t[-2]:
github norbusan / calibre-debian / src / calibre / utils / apsw_shell.py View on Github external
master="sqlite_temp_master"
                else:
                    master="[%s].sqlite_master" % (db,)
                for row in cur.execute("select * from "+master).fetchall():
                    for col in (1,2):
                        if row[col] not in other and not row[col].startswith("sqlite_"):
                            other.append(row[col])
                    if row[0]=="table":
                        try:
                            for table in cur.execute("pragma [%s].table_info([%s])" % (db, row[1],)).fetchall():
                                if table[1] not in other:
                                    other.append(table[1])
                                for item in table[2].split():
                                    if item not in other:
                                        other.append(item)
                        except apsw.SQLError:
                            # See https://code.google.com/p/apsw/issues/detail?id=86
                            pass

            self._completion_cache=[self._sqlite_keywords, self._sqlite_functions, self._sqlite_special_names, collations, databases, other]
            for i in range(len(self._completion_cache)):
                self._completion_cache[i].sort()

        # be somewhat sensible about pragmas
        if "pragma " in line.lower():
            t=self._get_prev_tokens(line.lower(), end)

            # pragma foo = bar
            if len(t)>2 and t[-3]=="pragma":
                # t[-2] should be a valid one
                for p in self._pragmas:
                    if p.replace("=","")==t[-2]:
github AFFT-520 / Android-Free-Forensic-Toolkit / pkg / win32 / build / src / report / whatsapp / maketable.py View on Github external
reportfile.write('None')
						else:
							name = str(entry2)
							if os.path.isfile(os.path.join(case, "extracted data", "whatsapp", "Media", "WhatsApp Images", name)):
								file = os.path.join(case, "extracted data", "whatsapp", "Media", "WhatsApp Images", name)
								reportfile.write("<img height="\&quot;200\&quot;" width="\&quot;200\&quot;" src="&quot; + file + &quot;">")
								reportfile.write("/Media/WhatsApp Images/" + name + "")
							elif os.path.isfile(os.path.join(case, "extracted data", "whatsapp", "Media", "WhatsApp Images", "Sent", name)):
								file = os.path.join(case, "extracted data", "whatsapp", "Media", "WhatsApp Images", "Sent", name)
								reportfile.write("<img height="\&quot;200\&quot;" width="\&quot;200\&quot;" src="&quot; + file + &quot;">")
								reportfile.write("/Media/WhatsApp Images/Sent/" + name + "")
							else:
								reportfile.write("[Not Found] " + name + "")
								reportfile.write("" + name + "")							
				reportfile.write("") ##closes the table row
	except apsw.SQLError:
		print("Error! could not make report!")
github AFFT-520 / Android-Free-Forensic-Toolkit / pkg / win32 / build / build / nsis / report / contacts / maketable.py View on Github external
for name in row2:
						reportfile.write("" + str(name) + "")
					
				reportfile.write("" + reportfile_cursor2.execute("SELECT normalized_number FROM phone_lookup where raw_contact_id = " + str(entry)) + "")
				for row2 in reportfile_cursor2.execute("SELECT normalized_number FROM phone_lookup where raw_contact_id = " + str(entry)):								
					for number in row2:
						reportfile.write("" + str(number) + "")
				for row2 in reportfile_cursor2.execute("SELECT account_type FROM view_raw_contacts where _id = " + str(entry)):				
					for acctype in row2:
						reportfile.write("" + str(acctype) + "")
				for row2 in reportfile_cursor2.execute("SELECT account_name FROM view_raw_contacts where _id = " + str(entry)):				
					for accname in row2:
						reportfile.write("" + str(accname) + "")
			
				reportfile.write("")
	except apsw.SQLError:
		for row1 in reportfile_cursor1.execute("SELECT _id FROM view_raw_contacts"):
			for entry in row1:	
				reportfile.write("")					
				for row2 in reportfile_cursor2.execute("SELECT display_name FROM view_raw_contacts where _id = " + str(entry)):
					for name in row2:
						reportfile.write("" + str(name) + "")
				for row2 in reportfile_cursor2.execute("SELECT COUNT (normalized_number) FROM phone_lookup where raw_contact_id = " + str(entry)):								
					for count in row2:
						if count == 0:
							reportfile.write("None")					
						elif count == 1:
							for row2 in reportfile_cursor2.execute("SELECT normalized_number FROM phone_lookup where raw_contact_id = " + str(entry)):								
								for number in row2:
									reportfile.write("" + str(number) + "")
						elif count &gt; 1:
							written = 1
github Tribler / tribler / Tribler / Core / CacheDB / sqlitecachedb.py View on Github external
sql_script = f.read()
                f.close()
            except IOError as e:
                msg = u"Failed to load SQL script %s: %s" % (self.db_script_path, e)
                raise IOError(msg)

            cursor.execute(sql_script)

        if self.db_script_path is not None:
            # read database version
            self._logger.info(u"Reading database version...")
            try:
                version_str, = cursor.execute(u"SELECT value FROM MyInfo WHERE entry == 'version'").next()
                self._version = int(version_str)
                self._logger.info(u"Current database version is %s", self._version)
            except (StopIteration, SQLError) as e:
                msg = u"Failed to load database version: %s" % e
                raise CorruptedDatabaseError(msg)
        else:
            self._version = 1