Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. import apsw
  2.  
  3. class TestVTable:
  4.     def __init__(self, conn):
  5.         self.conn = conn
  6.  
  7.     def Open(self):
  8.         return TestCursor(self)
  9.  
  10.     def BestIndex(self, *args):
  11.         return None
  12.  
  13. class TestCursor:
  14.     def __init__(self, table):
  15.         self.table              = table
  16.         self.offset             = 0
  17.  
  18.     def Filter(self, indexnum, indexname, constraintargs):
  19.         pass
  20.  
  21.     def Column(self, num):
  22.         if num == -1:
  23.             return self.offset
  24.         else:
  25.             return 'blah'
  26.  
  27.     def Rowid(self):
  28.         return self.offset
  29.  
  30.     def Next(self):
  31.         self.offset += 1
  32.  
  33.     def Eof(self):
  34.         return self.offset > 0
  35.  
  36.     def Close(self):
  37.         cur=db.cursor()
  38.         for i in range(5):
  39.             cur.execute("insert into timing values ('name',?)", (i,))
  40.         cur.close()
  41.  
  42. class TestVTModule:
  43.  
  44.     def Create( self, connection, modulename, databasename, tablename, *args ):
  45.         return "create table ignored (name,value)", TestVTable(connection)
  46.  
  47. # memory database
  48. db=apsw.Connection("")
  49. cursor=db.cursor()
  50. cursor.execute("create table timing (name,totalms)")
  51.  
  52. mod = TestVTModule()
  53. db.createmodule('testvt', mod)
  54.  
  55. cursor.execute("create virtual table blah using testvt()")
  56. cursor.execute("create table abc as select * from blah")
  57. cursor.execute("create table xyz as select * from blah") # fails on this line
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement