Class: Coopy::SqlTable

Inherits:
Object
  • Object
show all
Defined in:
lib/lib/coopy/sql_table.rb

Instance Method Summary collapse

Constructor Details

#initialize(db, name, helper = nil) ⇒ SqlTable

Returns a new instance of SqlTable.



7
8
9
10
11
12
13
14
15
16
# File 'lib/lib/coopy/sql_table.rb', line 7

def initialize(db,name,helper = nil)
  @db = db
  @name = name
  @helper = helper
  @helper = db.get_helper if helper == nil
  @cache = {}
  @h = -1
  @id2rid = nil
  self.get_columns
end

Instance Method Details

#alter_columns(columns) ⇒ Object



217
218
219
220
221
# File 'lib/lib/coopy/sql_table.rb', line 217

def alter_columns(columns)
  result = @helper.alter_columns(@db,@name,columns)
  @columns = nil
  result
end

#apply_flags(flags) ⇒ Object



272
273
274
# File 'lib/lib/coopy/sql_table.rb', line 272

def apply_flags(flags)
  false
end

#as_table ⇒ Object



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/lib/coopy/sql_table.rb', line 238

def as_table 
  pct = 3
  self.get_columns
  w = @column_names.length
  mt = ::Coopy::SimpleTable.new(w + 1,pct)
  mt.set_cell(0,0,"@")
  mt.set_cell(0,1,"type")
  mt.set_cell(0,2,"pkey")
  begin
    _g = 0
    while(_g < w) 
      x = _g
      _g+=1
      i = x + 1
      mt.set_cell(i,0,@column_names[x])
      mt.set_cell(i,1,@columns[x].type_value)
      mt.set_cell(i,2,((@columns[x].primary) ? 1 : 0))
    end
  end
  mt
end

#change_row(rc) ⇒ Object



223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/lib/coopy/sql_table.rb', line 223

def change_row(rc)
  if @helper == nil 
    puts "No sql helper"
    return false
  end
  if rc.action == "+++" 
    return @helper.insert(@db,@name,rc.val)
  elsif rc.action == "---" 
    return @helper._delete(@db,@name,rc.cond)
  elsif rc.action == "->" 
    return @helper.update(@db,@name,rc.cond,rc.val)
  end
  false
end

#clear ⇒ Object



175
176
# File 'lib/lib/coopy/sql_table.rb', line 175

def clear 
end

#clone ⇒ Object



209
210
211
# File 'lib/lib/coopy/sql_table.rb', line 209

def clone 
  nil
end

#clone_meta(table = nil) ⇒ Object



268
269
270
# File 'lib/lib/coopy/sql_table.rb', line 268

def clone_meta(table = nil)
  nil
end

#fetch_columns ⇒ Object



311
312
313
314
# File 'lib/lib/coopy/sql_table.rb', line 311

def fetch_columns 
  self.get_columns
  @column_names
end

#fetch_row ⇒ Object



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/lib/coopy/sql_table.rb', line 286

def fetch_row 
  if @db.read 
    row = {}
    begin
      _g1 = 0
      _g = @column_names.length
      while(_g1 < _g) 
        i = _g1
        _g1+=1
        begin
          v = @db.get(i)
          begin
            value = v
            row[@column_names[i]] = value
          end
          v
        end
      end
    end
    return row
  end
  @db._end
  nil
end

#get_all_but_primary_key ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/lib/coopy/sql_table.rb', line 64

def get_all_but_primary_key 
  self.get_columns
  result = Array.new
  begin
    _g = 0
    _g1 = @columns
    while(_g < _g1.length) 
      col = _g1[_g]
      _g+=1
      next if col.is_primary_key
      result.push(col.get_name)
    end
  end
  result
end

#get_cell(x, y) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/lib/coopy/sql_table.rb', line 95

def get_cell(x,y)
  if @h >= 0 
    y = y - 1
    y = @id2rid[y] if y >= 0
  elsif y == 0 
    y = -1
  end
  if y < 0 
    self.get_columns
    return @columns[x].name
  end
  row = @cache[y]
  if row == nil 
    row = {}
    self.get_columns
    @db.begin_row(@name,y,@column_names)
    while(@db.read) 
      _g1 = 0
      _g = self.get_width
      while(_g1 < _g) 
        i = _g1
        _g1+=1
        begin
          v = @db.get(i)
          begin
            value = v
            row[i] = value
          end
          v
        end
      end
    end
    @db._end
    begin
      @cache[y] = row
      row
    end
  end
  begin
    this1 = @cache[y]
    this1.get(x)
  end
end

#get_cell_view ⇒ Object



163
164
165
# File 'lib/lib/coopy/sql_table.rb', line 163

def get_cell_view 
  ::Coopy::SimpleView.new
end

#get_column_names ⇒ Object



80
81
82
83
# File 'lib/lib/coopy/sql_table.rb', line 80

def get_column_names 
  self.get_columns
  @column_names
end

#get_data ⇒ Object



205
206
207
# File 'lib/lib/coopy/sql_table.rb', line 205

def get_data 
  nil
end

#get_database ⇒ Object



276
277
278
# File 'lib/lib/coopy/sql_table.rb', line 276

def get_database 
  @db
end

#get_height ⇒ Object



200
201
202
203
# File 'lib/lib/coopy/sql_table.rb', line 200

def get_height 
  return @h if @h >= 0
  -1
end

#get_meta ⇒ Object



213
214
215
# File 'lib/lib/coopy/sql_table.rb', line 213

def get_meta 
  self
end

#get_primary_key ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/lib/coopy/sql_table.rb', line 48

def get_primary_key 
  self.get_columns
  result = Array.new
  begin
    _g = 0
    _g1 = @columns
    while(_g < _g1.length) 
      col = _g1[_g]
      _g+=1
      next if !col.is_primary_key
      result.push(col.get_name)
    end
  end
  result
end

#get_quoted_column_name(name) ⇒ Object



91
92
93
# File 'lib/lib/coopy/sql_table.rb', line 91

def get_quoted_column_name(name)
  @db.get_quoted_column_name(name)
end

#get_quoted_table_name ⇒ Object



85
86
87
88
89
# File 'lib/lib/coopy/sql_table.rb', line 85

def get_quoted_table_name 
  return @quoted_table_name if @quoted_table_name != nil
  @quoted_table_name = @db.get_quoted_table_name(@name)
  @quoted_table_name
end

#get_row_stream ⇒ Object



280
281
282
283
284
# File 'lib/lib/coopy/sql_table.rb', line 280

def get_row_stream 
  self.get_columns
  @db._begin("SELECT * FROM " + _hx_str(self.get_quoted_table_name) + " ORDER BY ?",[@db.rowid],@column_names)
  self
end

#get_width ⇒ Object



195
196
197
198
# File 'lib/lib/coopy/sql_table.rb', line 195

def get_width 
  self.get_columns
  @columns.length
end

#height ⇒ Object



190
# File 'lib/lib/coopy/sql_table.rb', line 190

def height() get_height end

#height=(__v) ⇒ Object



191
# File 'lib/lib/coopy/sql_table.rb', line 191

def height=(__v) @height = __v end

#insert_or_delete_columns(fate, wfate) ⇒ Object



182
183
184
# File 'lib/lib/coopy/sql_table.rb', line 182

def insert_or_delete_columns(fate,wfate)
  false
end

#insert_or_delete_rows(fate, hfate) ⇒ Object



178
179
180
# File 'lib/lib/coopy/sql_table.rb', line 178

def insert_or_delete_rows(fate,hfate)
  false
end

#is_resizable ⇒ Object



167
168
169
# File 'lib/lib/coopy/sql_table.rb', line 167

def is_resizable 
  false
end

#resize(w, h) ⇒ Object



171
172
173
# File 'lib/lib/coopy/sql_table.rb', line 171

def resize(w,h)
  false
end

#set_cell(x, y, c) ⇒ Object



159
160
161
# File 'lib/lib/coopy/sql_table.rb', line 159

def set_cell(x,y,c)
  puts "SqlTable cannot set cells yet"
end

#set_cell_cache(x, y, c) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/lib/coopy/sql_table.rb', line 139

def set_cell_cache(x,y,c)
  row = @cache[y]
  if row == nil 
    row = {}
    self.get_columns
    begin
      @cache[y] = row
      row
    end
  end
  begin
    v = c
    begin
      value = v
      row[x] = value
    end
    v
  end
end

#trim_blank ⇒ Object



186
187
188
# File 'lib/lib/coopy/sql_table.rb', line 186

def trim_blank 
  false
end

#use_for_column_changes ⇒ Object



260
261
262
# File 'lib/lib/coopy/sql_table.rb', line 260

def use_for_column_changes 
  true
end

#use_for_row_changes ⇒ Object



264
265
266
# File 'lib/lib/coopy/sql_table.rb', line 264

def use_for_row_changes 
  true
end

#width ⇒ Object



192
# File 'lib/lib/coopy/sql_table.rb', line 192

def width() get_width end

#width=(__v) ⇒ Object



193
# File 'lib/lib/coopy/sql_table.rb', line 193

def width=(__v) @width = __v end