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



221
222
223
224
225
# File 'lib/lib/coopy/sql_table.rb', line 221

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

#apply_flags(flags) ⇒ Object



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

def apply_flags(flags)
  false
end

#as_tableObject



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/lib/coopy/sql_table.rb', line 242

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,"key")
  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) ? "primary" : ""))
    end
  end
  mt
end

#change_row(rc) ⇒ Object



227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/lib/coopy/sql_table.rb', line 227

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

#clearObject



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

def clear 
end

#cloneObject



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

def clone 
  nil
end

#clone_meta(table = nil) ⇒ Object



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

def clone_meta(table = nil)
  nil
end

#createObject



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

def create 
  nil
end

#fetch_columnsObject



323
324
325
326
# File 'lib/lib/coopy/sql_table.rb', line 323

def fetch_columns 
  self.get_columns
  @column_names
end

#fetch_rowObject



298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/lib/coopy/sql_table.rb', line 298

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_keyObject



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_viewObject



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

def get_cell_view 
  ::Coopy::SimpleView.new
end

#get_column_namesObject



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

def get_column_names 
  self.get_columns
  @column_names
end

#get_dataObject



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

def get_data 
  nil
end

#get_databaseObject



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

def get_database 
  @db
end

#get_heightObject



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

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

#get_metaObject



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

def get_meta 
  self
end

#get_nameObject



328
329
330
# File 'lib/lib/coopy/sql_table.rb', line 328

def get_name 
  @name.to_s
end

#get_primary_keyObject



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_nameObject



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_streamObject



284
285
286
287
288
# File 'lib/lib/coopy/sql_table.rb', line 284

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_widthObject



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

def get_width 
  self.get_columns
  @columns.length
end

#heightObject



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_nestedObject



290
291
292
# File 'lib/lib/coopy/sql_table.rb', line 290

def is_nested 
  false
end

#is_resizableObject



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

def is_resizable 
  false
end

#is_sqlObject



294
295
296
# File 'lib/lib/coopy/sql_table.rb', line 294

def is_sql 
  true
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_blankObject



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

def trim_blank 
  false
end

#use_for_column_changesObject



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

def use_for_column_changes 
  true
end

#use_for_row_changesObject



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

def use_for_row_changes 
  true
end

#widthObject



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