Class: DBI::DatabaseHandle
Instance Attribute Summary
Attributes inherited from Handle
#handle, #trace_mode, #trace_output
Instance Method Summary
collapse
#conv_param
Methods inherited from Handle
#func, #initialize, #trace
Constructor Details
This class inherits a constructor from DBI::Handle
Instance Method Details
#[](attr) ⇒ Object
590
591
592
593
|
# File 'lib/dbi.rb', line 590
def [] (attr)
raise InterfaceError, "Database connection was already closed!" if @handle.nil?
@handle[attr]
end
|
#[]=(attr, val) ⇒ Object
595
596
597
598
|
# File 'lib/dbi.rb', line 595
def []= (attr, val)
raise InterfaceError, "Database connection was already closed!" if @handle.nil?
@handle[attr] = val
end
|
#columns(table) ⇒ Object
550
551
552
553
|
# File 'lib/dbi.rb', line 550
def columns( table )
raise InterfaceError, "Database connection was already closed!" if @handle.nil?
@handle.columns( table ).collect {|col| ColumnInfo.new(col) }
end
|
#commit ⇒ Object
565
566
567
568
|
# File 'lib/dbi.rb', line 565
def commit
raise InterfaceError, "Database connection was already closed!" if @handle.nil?
@handle.commit
end
|
#connected? ⇒ Boolean
476
477
478
|
# File 'lib/dbi.rb', line 476
def connected?
not @handle.nil?
end
|
#disconnect ⇒ Object
480
481
482
483
484
|
# File 'lib/dbi.rb', line 480
def disconnect
raise InterfaceError, "Database connection was already closed!" if @handle.nil?
@handle.disconnect
@handle = nil
end
|
#do(stmt, *bindvars) ⇒ Object
518
519
520
521
|
# File 'lib/dbi.rb', line 518
def do(stmt, *bindvars)
raise InterfaceError, "Database connection was already closed!" if @handle.nil?
@handle.do(stmt, *conv_param(*bindvars))
end
|
#execute(stmt, *bindvars) ⇒ Object
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
|
# File 'lib/dbi.rb', line 502
def execute(stmt, *bindvars)
raise InterfaceError, "Database connection was already closed!" if @handle.nil?
sth = StatementHandle.new(@handle.execute(stmt, *conv_param(*bindvars)), true, false)
sth.trace(@trace_mode, @trace_output)
if block_given?
begin
yield sth
ensure
sth.finish unless sth.finished?
end
else
return sth
end
end
|
#ping ⇒ Object
555
556
557
558
|
# File 'lib/dbi.rb', line 555
def ping
raise InterfaceError, "Database connection was already closed!" if @handle.nil?
@handle.ping
end
|
#prepare(stmt) ⇒ Object
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
|
# File 'lib/dbi.rb', line 486
def prepare(stmt)
raise InterfaceError, "Database connection was already closed!" if @handle.nil?
sth = StatementHandle.new(@handle.prepare(stmt), false)
sth.trace(@trace_mode, @trace_output)
if block_given?
begin
yield sth
ensure
sth.finish unless sth.finished?
end
else
return sth
end
end
|
#quote(value) ⇒ Object
560
561
562
563
|
# File 'lib/dbi.rb', line 560
def quote(value)
raise InterfaceError, "Database connection was already closed!" if @handle.nil?
@handle.quote(value)
end
|
#rollback ⇒ Object
570
571
572
573
|
# File 'lib/dbi.rb', line 570
def rollback
raise InterfaceError, "Database connection was already closed!" if @handle.nil?
@handle.rollback
end
|
#select_all(stmt, *bindvars, &p) ⇒ Object
532
533
534
535
536
537
538
539
540
541
542
543
|
# File 'lib/dbi.rb', line 532
def select_all(stmt, *bindvars, &p)
raise InterfaceError, "Database connection was already closed!" if @handle.nil?
rows = nil
execute(stmt, *bindvars) do |sth|
if block_given?
sth.each(&p)
else
rows = sth.fetch_all
end
end
return rows
end
|
#select_one(stmt, *bindvars) ⇒ Object
523
524
525
526
527
528
529
530
|
# File 'lib/dbi.rb', line 523
def select_one(stmt, *bindvars)
raise InterfaceError, "Database connection was already closed!" if @handle.nil?
row = nil
execute(stmt, *bindvars) do |sth|
row = sth.fetch
end
row
end
|
#tables ⇒ Object
545
546
547
548
|
# File 'lib/dbi.rb', line 545
def tables
raise InterfaceError, "Database connection was already closed!" if @handle.nil?
@handle.tables
end
|
#transaction ⇒ Object
575
576
577
578
579
580
581
582
583
584
585
586
587
|
# File 'lib/dbi.rb', line 575
def transaction
raise InterfaceError, "Database connection was already closed!" if @handle.nil?
raise InterfaceError, "No block given" unless block_given?
commit
begin
yield self
commit
rescue Exception
rollback
raise
end
end
|