Module: JDBCHelper::SQL Deprecated

Defined in:
lib/jdbc-helper/sql/sql.rb,
lib/jdbc-helper/sql/expression.rb

Overview

Deprecated.

Class Method Summary collapse

Class Method Details

.check(expr, is_name = false) ⇒ Object

Deprecated.

FIXME: Naive protection for SQL Injection TODO: check caching?

Raises:

  • (ArgumentError)


100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/jdbc-helper/sql/sql.rb', line 100

def self.check expr, is_name = false
  return nil if expr.nil?

  tag = is_name ? 'Object name' : 'Expression'
  test = expr.gsub(/'[^']*'/, '').gsub(/`[^`]*`/, '').gsub(/"[^"]*"/, '').strip
  raise ArgumentError.new("#{tag} cannot contain (unquoted) semi-colons: #{expr}") if test.include?(';')
  raise ArgumentError.new("#{tag} cannot contain (unquoted) comments: #{expr}") if test.match(%r{--|/\*|\*/})
  raise ArgumentError.new("Unclosed quotation mark: #{expr}") if test.match(/['"`]/)
  raise ArgumentError.new("#{tag} is blank") if test.empty?

  if is_name
    raise ArgumentError.new(
      "#{tag} cannot contain (unquoted) parentheses: #{expr}") if test.match(%r{\(|\)})
  end

  return expr
end

.count(table, conds = nil) ⇒ Object

Deprecated.

Generates count SQL with the given conditions



87
88
89
# File 'lib/jdbc-helper/sql/sql.rb', line 87

def self.count table, conds = nil
  SQLHelper.count :table => table, :where => conds, :prepared => false
end

.delete(table, conds = nil) ⇒ Object

Deprecated.

Generates delete SQL with the given conditions



93
94
95
# File 'lib/jdbc-helper/sql/sql.rb', line 93

def self.delete table, conds = nil
  SQLHelper.delete :table => table, :where => conds, :prepared => false
end

.expr(sql) ⇒ JDBCHelper::SQL::Expression

Deprecated.

Generate SQL snippet, prevents the string from being quoted.

Parameters:

  • SQL (String)

    snippet

Returns:

  • (JDBCHelper::SQL::Expression)

Since:

  • 0.7.0



14
15
16
# File 'lib/jdbc-helper/sql/expression.rb', line 14

def self.expr sql
  { :sql => sql }
end

.ge(v) ⇒ JDBCHelper::SQL::Expression

Deprecated.

Greater-than-or-equal-to expression for where clauses

Returns:

  • (JDBCHelper::SQL::Expression)

Since:

  • 0.7.0



56
57
58
# File 'lib/jdbc-helper/sql/expression.rb', line 56

def self.ge v
  { :ge => v }
end

.gt(v) ⇒ JDBCHelper::SQL::Expression

Deprecated.

Greater-than expression for where clauses

Returns:

  • (JDBCHelper::SQL::Expression)

Since:

  • 0.7.0



32
33
34
# File 'lib/jdbc-helper/sql/expression.rb', line 32

def self.gt v
  { :gt => v }
end

.insert(table, data_hash) ⇒ Object

Deprecated.

Generates insert SQL with hash



52
53
54
# File 'lib/jdbc-helper/sql/sql.rb', line 52

def self.insert table, data_hash
  SQLHelper.insert :table => table, :data => data_hash, :prepared => false
end

.insert_ignore(table, data_hash) ⇒ Object

Deprecated.

Generates insert ignore SQL (Non-standard syntax)



58
59
60
# File 'lib/jdbc-helper/sql/sql.rb', line 58

def self.insert_ignore table, data_hash
  SQLHelper.insert_ignore :table => table, :data => data_hash, :prepared => false
end

.le(v) ⇒ JDBCHelper::SQL::Expression

Deprecated.

Less-than-or-equal-to expression for where clauses

Returns:

  • (JDBCHelper::SQL::Expression)

Since:

  • 0.7.0



48
49
50
# File 'lib/jdbc-helper/sql/expression.rb', line 48

def self.le v
  { :le => v }
end

.like(v) ⇒ JDBCHelper::SQL::Expression

Deprecated.

Like expression for where clauses

Returns:

  • (JDBCHelper::SQL::Expression)

Raises:

  • (ArgumentError)

Since:

  • 0.7.0



72
73
74
75
# File 'lib/jdbc-helper/sql/expression.rb', line 72

def self.like v
  raise ArgumentError, "expected String" unless v.is_a?(String)
  { :like => v }
end

.lt(v) ⇒ JDBCHelper::SQL::Expression

Deprecated.

Less-than expression for where clauses

Returns:

  • (JDBCHelper::SQL::Expression)

Since:

  • 0.7.0



40
41
42
# File 'lib/jdbc-helper/sql/expression.rb', line 40

def self.lt v
  { :lt => v }
end

.ne(v) ⇒ JDBCHelper::SQL::Expression

Deprecated.

Not-equal expression for where clauses

Returns:

  • (JDBCHelper::SQL::Expression)

Since:

  • 0.7.0



64
65
66
# File 'lib/jdbc-helper/sql/expression.rb', line 64

def self.ne v
  { :ne => v }
end

.not_like(v) ⇒ JDBCHelper::SQL::Expression

Deprecated.

“Not like” expression for where clauses

Returns:

  • (JDBCHelper::SQL::Expression)

Raises:

  • (ArgumentError)

Since:

  • 0.7.0



81
82
83
84
# File 'lib/jdbc-helper/sql/expression.rb', line 81

def self.not_like v
  raise ArgumentError, "expected String" unless v.is_a?(String)
  { :not => { :like => v } }
end

.not_nilJDBCHelper::SQL::Expression Also known as: not_null

Deprecated.

“is not null” expression for where clauses

Returns:

  • (JDBCHelper::SQL::Expression)


21
22
23
# File 'lib/jdbc-helper/sql/expression.rb', line 21

def self.not_nil
  { :not => nil }
end

.order(*criteria) ⇒ Object

Deprecated.

Generates SQL order by cluase with the given conditions.



43
44
45
# File 'lib/jdbc-helper/sql/sql.rb', line 43

def self.order *criteria
  SQLHelper.order(*criteria)
end

.replace(table, data_hash) ⇒ Object

Deprecated.

Generates replace SQL (Non-standard syntax)



64
65
66
# File 'lib/jdbc-helper/sql/sql.rb', line 64

def self.replace table, data_hash
  SQLHelper.replace :table => table, :data => data_hash, :prepared => false
end

.select(table, opts = {}) ⇒ Object

Deprecated.

Generates select SQL with the given conditions



77
78
79
80
81
82
83
# File 'lib/jdbc-helper/sql/sql.rb', line 77

def self.select table, opts = {}
  SQLHelper.select :table    => table,
                   :project  => opts[:select],
                   :where    => opts[:where],
                   :order    => opts[:order],
                   :prepared => false
end

.update(table, data_hash, where) ⇒ Object

Deprecated.

Generates update SQL with hash. :where element of the given hash is taken out to generate where clause.



71
72
73
# File 'lib/jdbc-helper/sql/sql.rb', line 71

def self.update table, data_hash, where
  SQLHelper.update :table => table, :data => data_hash, :where => where, :prepared => false
end

.value(data) ⇒ Object

Deprecated.

Formats the given data so that it can be injected into SQL



25
26
27
# File 'lib/jdbc-helper/sql/sql.rb', line 25

def self.value data
  SQLHelper.quote(data)
end

.where(*conds) ⇒ Object

Deprecated.

Generates SQL where cluase with the given conditions. Parameter can be either Hash of String.



32
33
34
# File 'lib/jdbc-helper/sql/sql.rb', line 32

def self.where *conds
  SQLHelper.where(*conds)
end

.where_prepared(*conds) ⇒ Object

Deprecated.


37
38
39
# File 'lib/jdbc-helper/sql/sql.rb', line 37

def self.where_prepared *conds
  SQLHelper.where_prepared(*conds)
end