File: dbTable.py

package info (click to toggle)
pythoncard 0.8.2-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 8,452 kB
  • sloc: python: 56,787; makefile: 56; sh: 22
file content (75 lines) | stat: -rw-r--r-- 2,120 bytes parent folder | download | duplicates (4)
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
from wx import grid

class DBTable(grid.PyGridTableBase):
    """Class to wrap a database table that can be assigned to a grid
    
    Inspired by wxPyDBAPITable by Nathan R Yergler
    """
    def __init__(self, db, tableName):
        grid.PyGridTableBase.__init__(self)
        self.__db=db
        self.tableName=tableName
        self.getData(tableName)

    def getData(self, tableName):
        "Execute <stmt> and return the rows to our internal data structure"
        # Should tableName be a method argument or should we use self.tableName?
        self.__rows=self.__db.getRows(tableName)
        self._rowCount=len(self.__rows)
        self._colNames=[col[0] for col in self.__db.getColumns(tableName)]
        self._colCount=len(self._colNames)

    # Table level methods
    def GetNumberRows(self):
        return self._rowCount

    def GetNumberCols(self):
        return self._colCount

    def AppendRows(self, numRows=1):
        # Implement this when we want to modify data
        # Should just be a simple insert (?)
        return True

    # Cell level values
    def IsEmptyCell(self, row, col):
        if self.__rows[row][col] == "" or self.__rows[row][col] is None:
            return True
        else:
            return False

    def GetValue(self, row, col):
        return self.__rows[row][col]

    def SetValue(self, row, col, valstr):
        # Implement this when we want to modify data
        # Should just be a simple update (?)
        return True

    # Label methods
    def GetRowLabelValue(self, row):
        # A record number will do fine, thanks
        return row+1

    def GetColLabelValue(self, col):
        return self._colNames[col]

    def SetRowLavelValue(self, row, label):
        # Disable this for now
        pass

    def SetColLabelValue(self, row, label):
        # Disable this for now
        pass

    # Miscellaneous methods
    def refresh(self):
        if self.__stmt:
            self.getData(self.__stmt)

    def GetRowLabelList(self):
        # Not today thank you
        pass

    def GetColLabelList(self):
        return self._colNames