svlad

Check-in [4fc6193906]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:SQLITE logic now works. Table editing needs to be solved.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:4fc6193906761d274a2601eff6289f47b9d0bbed
User & Date: severak 2012-05-05 21:20:58
Context
2012-06-04
22:25
Added grafikon from Margarita suite. check-in: 31fdc1d58d user: severak tags: trunk
2012-05-05
21:20
SQLITE logic now works. Table editing needs to be solved. check-in: 4fc6193906 user: severak tags: trunk
16:30
Logic separated from presentation. check-in: f83fb14078 user: severak tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to logic/sqlite.lua.

1
2
3
4
5
6
7
8
9
10


11
12
13
14
15
16
17

18
19
20

21
22
23
24

25
26




















27
28
29

30
31






32
33




34
35


36


37










38


39
40
41
42



















43
44
45
module("logic.sqlite",package.seeall)
require "jo"
require "luasql.sqlite3"
original=require "logic.basic"

function showresult(dotaz)
  res=assert(conn:execute(dotaz))
  if type(res)=="number" then
    VCL.ShowMessage("Zmeneno "..res.." radek.")
  else


    cnames=res:getcolnames()
    tabl.colCount=#cnames+1
    tabl.rowCount=1
    for k,v in pairs(cnames) do
      tabl:SetCell(k,0,v)
    end
    row=res:fetch({})

    while row do
      r=tabl:AddRow()
      tabl:SetCell(0,r,r)

      for k,v in pairs(row) do
        tabl:SetCell(k,r,v)
      end
      row=res:fetch(row)   

    end
    res:close()




















  end
end



logic=original:rewriteSlots({







   init=function(self)




      env=luasql.sqlite3()
      conn=assert(env:connect("prachy.db3"))


   end,













   processQuery=function(self,sql)


      passed,mesg=pcall(showresult,dotaz)
      if not passed then
        VCL.ShowMessage(mesg)  
      end  



















   end  

})





|




>
>

<
<

|


>

<
|
>

|

|
>


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



>

<
>
>
>
>
>
>


>
>
>
>

|
>
>
|
>
>
|
>
>
>
>
>
>
>
>
>
>

>
>
|



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



1
2
3
4
5
6
7
8
9
10
11
12
13


14
15
16
17
18
19

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
module("logic.sqlite",package.seeall)
require "jo"
require "luasql.sqlite3"
original=require "logic.basic"

function showresult(conn,dotaz)
  res=assert(conn:execute(dotaz))
  if type(res)=="number" then
    VCL.ShowMessage("Zmeneno "..res.." radek.")
  else
    local rowids={}
    local cols={}
    cnames=res:getcolnames()


    for k,v in pairs(cnames) do
      GUI.setCell(k,0,v)
    end
    row=res:fetch({})
    local r=1
    while row do

      GUI.setCell(0,r,r)
      rowids[r]=row[1]
      for k,v in pairs(row) do
        GUI.setCell(k,r,v)
      end
      row=res:fetch(row)
      r=r+1   
    end
    res:close()
    return rowids,cnames
  end
end

function in_table ( e, t )
  for _,v in pairs(t) do
    if (v==e) then return true end
  end
  return false
end

function rows (connection, sql_statement)
  local cursor = assert (connection:execute (sql_statement))
  return function ()
    local data=cursor:fetch()
    if data then
      return data
    else
      cursor:close()
    end
  end
end

logic=original.logic:rewriteSlots({


   tables={},
   prevX=0,
   prevY=0,
   prevTxt="",
   rowids={},
   cols={},

   init=function(self)
      dbname="svlad.db3"
      if arg[2] then
        dbname=arg[2]
      end
      env=luasql.sqlite3()
      self.db=assert(env:connect(dbname))
      for name in rows(self.db,"SELECT name FROM sqlite_master WHERE type='table'") do
        self.tables[#self.tables+1]=name
      end
      GUI.setTableList(self.tables)
   end,
   
   tableListChange=function(self,name)
      GUI.resetTable()
      if in_table(name,self.tables) then
        --print("SELECT * FROM "..name)
        self.rowids,self.cols=showresult(self.db,"SELECT rowid, * FROM "..name.." LIMIT 500")  
      end
      self.table=name
      self.editable=true
   end,
    
   processQuery=function(self,sql)
      GUI.resetTable()
      self.editable=false
      passed,mesg=pcall(showresult,self.db,dotaz)
      if not passed then
        VCL.ShowMessage(mesg)  
      end  
   end,
   
   editCell=function(self,x,y,v)
    if x==self.prevX and y==self.prevY then
      if self.prevTxt==v then
        if self.editable then
          print(string.format("UPDATE %s SET %s=%q WHERE rowid=%i",self.table,self.cols[x],v,self.rowids[y]))
        end
      end
      self.prevTxt=v
    else
      --print("Zmena cor",x,y,v)
      self.prevX=x
      self.prevY=y
    end
   end,
   
   close=function(self)
      self.db:close()
   end  

})

Changes to svlad.lua.

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
    tabl.colCount=1
    tabl.rowCount=1
  end,
  
  setCell=function(x,y,v)
    if tabl.rowCount<y+1 then
      tabl.rowCount=y+1
      print("+col")
    end
    if tabl.colCount<x+1 then
      tabl.colCount=x+1
      print("+row")
    end
    tabl:SetCell(x,y,v)
  end
}

menu={
  {caption="&Databases",submenu={







<



<







65
66
67
68
69
70
71

72
73
74

75
76
77
78
79
80
81
    tabl.colCount=1
    tabl.rowCount=1
  end,
  
  setCell=function(x,y,v)
    if tabl.rowCount<y+1 then
      tabl.rowCount=y+1

    end
    if tabl.colCount<x+1 then
      tabl.colCount=x+1

    end
    tabl:SetCell(x,y,v)
  end
}

menu={
  {caption="&Databases",submenu={