document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. \' Gambas class file
  2.  
  3. Private $hConn As New Connection
  4. Private $res As Result
  5.  
  6. Public Sub Form_Open()
  7.  
  8.   Dim iCount As Integer
  9.   Dim hTable As Table
  10.   Dim rTest As Result
  11.   Dim sql As String
  12.   \'define the gridview layout
  13.   GridView1.header = GridView.Horizontal
  14.   GridView1.grid = True
  15.   GridView1.Rows.count = 0
  16.   GridView1.Columns.count = 2
  17.   GridView1.Columns[0].text = "ID"
  18.   GridView1.Columns[1].text = "Value"
  19.   GridView1.Columns[0].width = 55
  20.   GridView1.Columns[1].width = 55
  21.   With $hConn
  22.     .Type = "sqlite"
  23.     .host = User.home
  24.     .name = ""
  25.   End With
  26.   \'delete an existing test.sqlite
  27.   If Exist(User.home & "/test.sqlite") Then
  28.     Kill User.home & "/test.sqlite"
  29.   Endif
  30.   \'create test.sqlite
  31.   $hConn.Open
  32.   $hConn.Databases.Add("test.sqlite")
  33.   $hconn.Close
  34.   \'define the table sampleTable
  35.   $hconn.name = "test.sqlite"
  36.   $hConn.Open
  37.   hTable = $hConn.Tables.Add("sampleTable")
  38.   hTable.Fields.Add("s_seq", db.Integer)
  39.   hTable.Fields.Add("s_rndm", db.Integer)
  40.   hTable.PrimaryKey = ["s_seq"]
  41.   hTable.Update
  42.   \'fill the table with generated data
  43.   $hconn.Begin
  44.   rTest = $hConn.Create("sampleTable")
  45.   For iCount = 1 To 10000
  46.     rTest!s_seq = iCount
  47.     rTest!s_rndm = Int(Rnd(0, 100))
  48.     rTest.Update
  49.   Next
  50.   $hConn.Commit
  51.   \'read the database
  52.   sql = "select s_seq as ID, s_rndm as Value from sampleTable"
  53.   $res = $hconn.Exec(sql)
  54. Catch
  55.   $hConn.Rollback
  56.   Message.Error(DConv(Error.Text))
  57.  
  58. End
  59.  
  60. Public Sub Form_Activate()
  61.   \'Al cambiar dos veces el numero de filas, se fuerza a que se rellene el gridview con el evento _Data()
  62.  
  63.   GridView1.Rows.Count = 0
  64.   GridView1.Rows.Count = $res.Count
  65.  
  66. End
  67.  
  68. Public Sub GridView1_Data(Row As Integer, Column As Integer)
  69.  
  70.   $res.moveTo(row)
  71.   GridView1.Data.text = Str($res[GridView1.Columns[column].text])
  72.  
  73. End
  74.  
  75. Public Sub Form_Close()
  76.  
  77.   $hconn.Close
  78.  
  79. End
');