Module: Ronin::Code::SQL::Functions

Included in:
Clause, InjectionExpr, StatementList
Defined in:
lib/ronin/code/sql/functions.rb

Overview

Methods for creating common SQL Functions.

Aggregate Functions collapse

Numeric Functions collapse

String Functions collapse

Instance Method Details

#abs(x) ⇒ Function

The ABS function.

Parameters:

Returns:



139
140
141
# File 'lib/ronin/code/sql/functions.rb', line 139

def abs(x)
  Function.new(:ABS,x)
end

#acos(x) ⇒ Function

The ACOS function.

Parameters:

Returns:



151
152
153
# File 'lib/ronin/code/sql/functions.rb', line 151

def acos(x)
  Function.new(:ACOS,x)
end

#ascii(string) ⇒ Function

The ASCII function.

Parameters:

Returns:



567
568
569
# File 'lib/ronin/code/sql/functions.rb', line 567

def ascii(string)
  Function.new(:ASCII,string)
end

#asin(x) ⇒ Function

The ASIN function.

Parameters:

Returns:



163
164
165
# File 'lib/ronin/code/sql/functions.rb', line 163

def asin(x)
  Function.new(:ASIN,x)
end

#atan(x) ⇒ Function

The ATAN function.

Parameters:

Returns:



175
176
177
# File 'lib/ronin/code/sql/functions.rb', line 175

def atan(x)
  Function.new(:ATAN,x)
end

#atan2(y, x) ⇒ Function

The ATAN2 function.

Parameters:

Returns:



189
190
191
# File 'lib/ronin/code/sql/functions.rb', line 189

def atan2(y,x)
  Function.new(:ATAN2,y,x)
end

#avg(field) ⇒ Function

The AVG function.

Parameters:

  • field (Field, Symbol)

    The field to aggregate.

Returns:



84
85
86
# File 'lib/ronin/code/sql/functions.rb', line 84

def avg(field)
  Function.new(:AVG,field)
end

#bin(n) ⇒ Function

The BIN function.

Parameters:

Returns:



579
580
581
# File 'lib/ronin/code/sql/functions.rb', line 579

def bin(n)
  Function.new(:BIN,n)
end

#bit_and(x) ⇒ Function

The BIT_AND function.

Parameters:

Returns:



201
202
203
# File 'lib/ronin/code/sql/functions.rb', line 201

def bit_and(x)
  Function.new(:BIT_AND,x)
end

#bit_count(x) ⇒ Function

The BIT_COUNT function.

Parameters:

Returns:



213
214
215
# File 'lib/ronin/code/sql/functions.rb', line 213

def bit_count(x)
  Function.new(:BIT_COUNT,x)
end

#bit_length(string) ⇒ Function

The BIT_LENGTH function.

Parameters:

Returns:



591
592
593
# File 'lib/ronin/code/sql/functions.rb', line 591

def bit_length(string)
  Function.new(:BIT_LENGTH,string)
end

#bit_or(x) ⇒ Function

The BIT_OR function.

Parameters:

Returns:



225
226
227
# File 'lib/ronin/code/sql/functions.rb', line 225

def bit_or(x)
  Function.new(:BIT_OR,x)
end

#ceil(x) ⇒ Function

The CEIL function.

Parameters:

Returns:



237
238
239
# File 'lib/ronin/code/sql/functions.rb', line 237

def ceil(x)
  Function.new(:CEIL,x)
end

#ceiling(x) ⇒ Function

The CEILING function.

Parameters:

Returns:



249
250
251
# File 'lib/ronin/code/sql/functions.rb', line 249

def ceiling(x)
  Function.new(:CEILING,x)
end

#char(*bytes) ⇒ Function

The CHAR function.

Parameters:

  • bytes (Array<Numeric>)

Returns:



603
604
605
# File 'lib/ronin/code/sql/functions.rb', line 603

def char(*bytes)
  Function.new(:CHAR,*bytes)
end

#char_length(string) ⇒ Function

The CHAR_LENGTH function.

Parameters:

Returns:



615
616
617
# File 'lib/ronin/code/sql/functions.rb', line 615

def char_length(string)
  Function.new(:CHAR_LENGTH,string)
end

#character_length(string) ⇒ Function

The CHARACTER_LENGTH function.

Parameters:

Returns:



627
628
629
# File 'lib/ronin/code/sql/functions.rb', line 627

def character_length(string)
  Function.new(:CHARACTER_LENGTH,string)
end

#concat(*strings) ⇒ Function

The CONCAT function.

Parameters:

Returns:



639
640
641
# File 'lib/ronin/code/sql/functions.rb', line 639

def concat(*strings)
  Function.new(:CONCAT,*strings)
end

#concat_ws(separator, *strings) ⇒ Function

The CONCAT_WS function.

Parameters:

Returns:



653
654
655
# File 'lib/ronin/code/sql/functions.rb', line 653

def concat_ws(separator,*strings)
  Function.new(:CONCAT_WS,separator,*strings)
end

#conv(number, from_base, to_base) ⇒ Function

The CONV function.

Parameters:

Returns:



669
670
671
# File 'lib/ronin/code/sql/functions.rb', line 669

def conv(number,from_base,to_base)
  Function.new(:CONV,number,from_base,to_base)
end

#cos(x) ⇒ Function

The COS function.

Parameters:

Returns:



261
262
263
# File 'lib/ronin/code/sql/functions.rb', line 261

def cos(x)
  Function.new(:COS,x)
end

#cot(x) ⇒ Function

The COT function.

Parameters:

Returns:



273
274
275
# File 'lib/ronin/code/sql/functions.rb', line 273

def cot(x)
  Function.new(:COT,x)
end

#count(field = :*) ⇒ Function

The COUNT function.

Parameters:

  • field (Field, Symbol) (defaults to: :*)

    The field to aggregate.

Returns:



45
46
47
# File 'lib/ronin/code/sql/functions.rb', line 45

def count(field=:*)
  Function.new(:COUNT,field)
end

#degrees(x) ⇒ Function

The DEGREES function.

Parameters:

Returns:



285
286
287
# File 'lib/ronin/code/sql/functions.rb', line 285

def degrees(x)
  Function.new(:DEGREES,x)
end

#elt(index, *strings) ⇒ Function

The ELT function.

Parameters:

Returns:



683
684
685
# File 'lib/ronin/code/sql/functions.rb', line 683

def elt(index,*strings)
  Function.new(:ELT,index,*strings)
end

#exp(x) ⇒ Function

The EXP function.

Parameters:

Returns:



297
298
299
# File 'lib/ronin/code/sql/functions.rb', line 297

def exp(x)
  Function.new(:EXP,x)
end

#export_set(bits, on, off, separator = nil, number_of_bits = nil) ⇒ Function

The EXPORT_SET function.

Parameters:

Returns:



703
704
705
706
707
708
709
710
711
# File 'lib/ronin/code/sql/functions.rb', line 703

def export_set(bits,on,off,separator=nil,number_of_bits=nil)
  if (separator && number_of_bits)
    Function.new(:EXPORT_SET,bits,on,off,separator,number_of_bits)
  elsif separator
    Function.new(:EXPORT_SET,bits,on,off,separator)
  else
    Function.new(:EXPORT_SET,bits,on,off)
  end
end

#field(*strings) ⇒ Function

The FIELD function.

Parameters:

Returns:



721
722
723
# File 'lib/ronin/code/sql/functions.rb', line 721

def field(*strings)
  Function.new(:FIELD,*strings)
end

#find_in_set(string, set) ⇒ Function

The FIND_IN_SET function.

Parameters:

Returns:



735
736
737
# File 'lib/ronin/code/sql/functions.rb', line 735

def find_in_set(string,set)
  Function.new(:FIND_IN_SET,string,set)
end

#floor(x) ⇒ Function

The FLOOR function.

Parameters:

Returns:



309
310
311
# File 'lib/ronin/code/sql/functions.rb', line 309

def floor(x)
  Function.new(:FLOOR,x)
end

#format(value, pattern) ⇒ Function

The FORMAT function.

Parameters:

Returns:



323
324
325
# File 'lib/ronin/code/sql/functions.rb', line 323

def format(value,pattern)
  Function.new(:FORMAT,value,pattern)
end

#glob(pattern, string) ⇒ Function

The GLOB function.

Parameters:

Returns:



749
750
751
# File 'lib/ronin/code/sql/functions.rb', line 749

def glob(pattern,string)
  Function.new(:GLOB,pattern,string)
end

#greatest(*values) ⇒ Function

The GREATEST function.

Parameters:

Returns:



335
336
337
# File 'lib/ronin/code/sql/functions.rb', line 335

def greatest(*values)
  Function.new(:GREATEST,*values)
end

#hex(value) ⇒ Function

The HEX function.

Parameters:

Returns:



761
762
763
# File 'lib/ronin/code/sql/functions.rb', line 761

def hex(value)
  Function.new(:HEX,value)
end

#insert(string, position, length, new_string) ⇒ Function

The INSERT function.

Parameters:

Returns:



779
780
781
# File 'lib/ronin/code/sql/functions.rb', line 779

def insert(string,position,length,new_string)
  Function.new(:INSERT,string,position,length,new_string)
end

#instr(string, sub_string) ⇒ Function

The INSTR function.

Parameters:

Returns:



793
794
795
# File 'lib/ronin/code/sql/functions.rb', line 793

def instr(string,sub_string)
  Function.new(:INSTR,string,sub_string)
end

#interval(*values) ⇒ Function

The INTERVAL function.

Parameters:

Returns:



347
348
349
# File 'lib/ronin/code/sql/functions.rb', line 347

def interval(*values)
  Function.new(:INTERVAL,*values)
end

#lcase(string) ⇒ Function

The LCASE function.

Parameters:

Returns:



805
806
807
# File 'lib/ronin/code/sql/functions.rb', line 805

def lcase(string)
  Function.new(:LCASE,string)
end

#least(*values) ⇒ Function

The LEAST function.

Parameters:

Returns:



359
360
361
# File 'lib/ronin/code/sql/functions.rb', line 359

def least(*values)
  Function.new(:LEAST,*values)
end

#left(string, length) ⇒ Function

The LEFT function.

Parameters:

Returns:



819
820
821
# File 'lib/ronin/code/sql/functions.rb', line 819

def left(string,length)
  Function.new(:LEFT,string,length)
end

#length(string) ⇒ Function

The LENGTH function.

Parameters:

Returns:



831
832
833
# File 'lib/ronin/code/sql/functions.rb', line 831

def length(string)
  Function.new(:LENGTH,string)
end

#like(x, y, options = nil) ⇒ Function

The LIKE function.

Returns:



841
842
843
844
845
# File 'lib/ronin/code/sql/functions.rb', line 841

def like(x,y,options=nil)
  if options then Function.new(:LIKE,x,y,options)
  else            Function.new(:LIKE,x,y)
  end
end

#load_file(file_name) ⇒ Function

The LOAD_FILE function.

Parameters:

Returns:



855
856
857
# File 'lib/ronin/code/sql/functions.rb', line 855

def load_file(file_name)
  Function.new(:LOAD_FILE,file_name)
end

#locate(substring, string, pos = nil) ⇒ Function

The LOCATE function.

Parameters:

Returns:



871
872
873
874
875
# File 'lib/ronin/code/sql/functions.rb', line 871

def locate(substring,string,pos=nil)
  if pos then Function.new(:LOCATE,substring,string,pos)
  else        Function.new(:LOCATE,substring,string)
  end
end

#log(b = nil, x) ⇒ Function

The LOG function.

Parameters:

Returns:



373
374
375
376
377
# File 'lib/ronin/code/sql/functions.rb', line 373

def log(b=nil,x)
  if b then Function.new(:LOG,b,x)
  else      Function.new(:LOG,x)
  end
end

#log10(x) ⇒ Function

The LOG10 function.

Parameters:

Returns:



387
388
389
# File 'lib/ronin/code/sql/functions.rb', line 387

def log10(x)
  Function.new(:LOG10,x)
end

#lower(string) ⇒ Function

The LOWER function.

Parameters:

Returns:



885
886
887
# File 'lib/ronin/code/sql/functions.rb', line 885

def lower(string)
  Function.new(:LOWER,string)
end

#lpad(string, length, pad_string) ⇒ Function

The LPAD function.

Parameters:

Returns:



901
902
903
# File 'lib/ronin/code/sql/functions.rb', line 901

def lpad(string,length,pad_string)
  Function.new(:LPAD,string,length,pad_string)
end

#ltrim(string) ⇒ Function

The LTRIM function.

Parameters:

Returns:



913
914
915
# File 'lib/ronin/code/sql/functions.rb', line 913

def ltrim(string)
  Function.new(:LTRIM,string)
end

#make_set(bits, *strings) ⇒ Function

The MAKE_SET function.

Parameters:

Returns:



927
928
929
# File 'lib/ronin/code/sql/functions.rb', line 927

def make_set(bits,*strings)
  Function.new(:MAKE_SET,bits,*strings)
end

#max(field) ⇒ Function

The MAX function.

Parameters:

  • field (Field, Symbol)

    The field to aggregate.

Returns:



58
59
60
# File 'lib/ronin/code/sql/functions.rb', line 58

def max(field)
  Function.new(:MAX,field)
end

#mid(string, position, length) ⇒ Function

The MID function.

Parameters:

Returns:



943
944
945
# File 'lib/ronin/code/sql/functions.rb', line 943

def mid(string,position,length)
  Function.new(:MID,string,position,length)
end

#min(field) ⇒ Function

The MIN function.

Parameters:

  • field (Field, Symbol)

    The field to aggregate.

Returns:



71
72
73
# File 'lib/ronin/code/sql/functions.rb', line 71

def min(field)
  Function.new(:MIN,field)
end

#mod(n, m) ⇒ Function

The MOD function.

Parameters:

Returns:



401
402
403
# File 'lib/ronin/code/sql/functions.rb', line 401

def mod(n,m)
  Function.new(:MOD,n,m)
end

#oct(number) ⇒ Function

The OCT function.

Parameters:

Returns:



955
956
957
# File 'lib/ronin/code/sql/functions.rb', line 955

def oct(number)
  Function.new(:OCT,number)
end

#octet_length(string) ⇒ Function

The OCTET_LENGTH function.

Parameters:

Returns:



967
968
969
# File 'lib/ronin/code/sql/functions.rb', line 967

def octet_length(string)
  Function.new(:OCTET_LENGTH,string)
end

#ord(string) ⇒ Function

The ORD function.

Parameters:

Returns:



979
980
981
# File 'lib/ronin/code/sql/functions.rb', line 979

def ord(string)
  Function.new(:ORD,string)
end

#piFunction

The PI function.

Returns:



411
412
413
# File 'lib/ronin/code/sql/functions.rb', line 411

def pi
  Function.new(:PI)
end

#position(expr) ⇒ Function

The POSITION function.

Parameters:

Returns:



991
992
993
# File 'lib/ronin/code/sql/functions.rb', line 991

def position(expr)
  Function.new(:POSITION,expr)
end

#pow(x, y) ⇒ Function

The POW function.

Parameters:

Returns:



425
426
427
# File 'lib/ronin/code/sql/functions.rb', line 425

def pow(x,y)
  Function.new(:POW,x,y)
end

#power(x, y) ⇒ Function

The POWER function.

Parameters:

Returns:



439
440
441
# File 'lib/ronin/code/sql/functions.rb', line 439

def power(x,y)
  Function.new(:POWER,x,y)
end

#quote(string) ⇒ Function

The QUOTE function.

Parameters:

Returns:



1003
1004
1005
# File 'lib/ronin/code/sql/functions.rb', line 1003

def quote(string)
  Function.new(:QUOTE,string)
end

#radians(x) ⇒ Function

The RADIANS function.

Parameters:

Returns:



451
452
453
# File 'lib/ronin/code/sql/functions.rb', line 451

def radians(x)
  Function.new(:RADIANS,x)
end

#rand(field) ⇒ Function

The RAND function.

Parameters:

  • field (Field, Symbol)

    The field to aggregate.

Returns:



123
124
125
# File 'lib/ronin/code/sql/functions.rb', line 123

def rand(field)
  Function.new(:RAND,field)
end

#randomFunction

The RANDOM function.

Returns:



461
462
463
# File 'lib/ronin/code/sql/functions.rb', line 461

def random
  Function.new(:RANDOM)
end

#repeat(string, count) ⇒ Function

The REPEAT function.

Parameters:

Returns:



1017
1018
1019
# File 'lib/ronin/code/sql/functions.rb', line 1017

def repeat(string,count)
  Function.new(:REPEAT,string,count)
end

#replace(string, from_string, to_string) ⇒ Function

The REPLACE function.

Parameters:

Returns:



1033
1034
1035
# File 'lib/ronin/code/sql/functions.rb', line 1033

def replace(string,from_string,to_string)
  Function.new(:REPLACE,string,from_string,to_string)
end

#reverse(string) ⇒ Function

The REVERSE function.

Parameters:

  • string (Field, Function, Symbol, String)

    The input String to reverse.

Returns:



1046
1047
1048
# File 'lib/ronin/code/sql/functions.rb', line 1046

def reverse(string)
  Function.new(:REVERSE,string)
end

#right(string, length) ⇒ Function

The RIGHT function.

Parameters:

  • string (Field, Function, Symbol, String)

    The input String to extract from.

  • length (Integer)

    The desired number of characters to extract.

Returns:



1062
1063
1064
# File 'lib/ronin/code/sql/functions.rb', line 1062

def right(string,length)
  Function.new(:RIGHT,string,length)
end

#round(x, d = nil) ⇒ Function

The ROUND function.

Parameters:

Returns:



475
476
477
478
479
# File 'lib/ronin/code/sql/functions.rb', line 475

def round(x,d=nil)
  if d then Function.new(:ROUND,x,d)
  else      Function.new(:ROUND,x)
  end
end

#rpad(string, length, pad_string) ⇒ Function

The RPAD function.

Parameters:

  • string (Field, Function, Symbol, String)

    The original String to pad.

  • length (Integer)

    The desired length of the String.

  • pad_string (Field, Function, Symbol, String)

    The String to pad with.

Returns:



1081
1082
1083
# File 'lib/ronin/code/sql/functions.rb', line 1081

def rpad(string,length,pad_string)
  Function.new(:RPAD,string,length,pad_string)
end

#rtrim(string) ⇒ Function

The RTRIM function.

Parameters:

  • string (Field, Function, Symbol, String)

    The original String to trim.

Returns:



1094
1095
1096
# File 'lib/ronin/code/sql/functions.rb', line 1094

def rtrim(string)
  Function.new(:RTRIM,string)
end

#sign(x) ⇒ Function

The SIGN function.

Parameters:

Returns:



489
490
491
# File 'lib/ronin/code/sql/functions.rb', line 489

def sign(x)
  Function.new(:SIGN,x)
end

#sin(x) ⇒ Function

The SIN function.

Parameters:

Returns:



501
502
503
# File 'lib/ronin/code/sql/functions.rb', line 501

def sin(x)
  Function.new(:SIN,x)
end

#sleep(secs) ⇒ Function

The SLEEP function.

Parameters:

  • secs (Numeric)

    The number of seconds to sleep for.

Returns:

Since:

  • 1.2.0



1247
1248
1249
# File 'lib/ronin/code/sql/functions.rb', line 1247

def sleep(secs)
  Function.new(:SLEEP,secs)
end

#soundex(string) ⇒ Function

The SOUNDEX function.

Parameters:

Returns:



1107
1108
1109
# File 'lib/ronin/code/sql/functions.rb', line 1107

def soundex(string)
  Function.new(:SOUNDEX,string)
end

#space(number) ⇒ Function

The SPACE function.

Parameters:

Returns:



1119
1120
1121
# File 'lib/ronin/code/sql/functions.rb', line 1119

def space(number)
  Function.new(:SPACE,number)
end

#sqrt(field) ⇒ Function

The SQRT function.

Parameters:

  • field (Field, Function, Symbol, Numeric)

    The field to aggregate.

Returns:



110
111
112
# File 'lib/ronin/code/sql/functions.rb', line 110

def sqrt(field)
  Function.new(:SQRT,field)
end

#std(field) ⇒ Function

The STD function.

Parameters:

Returns:



513
514
515
# File 'lib/ronin/code/sql/functions.rb', line 513

def std(field)
  Function.new(:STD,field)
end

#stddev(field) ⇒ Function

The STDDEV function.

Parameters:

Returns:



525
526
527
# File 'lib/ronin/code/sql/functions.rb', line 525

def stddev(field)
  Function.new(:STDDEV,field)
end

#strcmp(string1, string2) ⇒ Function

The STRCMP function.

Parameters:

Returns:



1133
1134
1135
# File 'lib/ronin/code/sql/functions.rb', line 1133

def strcmp(string1,string2)
  Function.new(:STRCMP,string1,string2)
end

#substring(string, position, length = nil) ⇒ Function

The SUBSTRING function.

Parameters:

  • string (Field, Function, Symbol, String)

    The original string.

  • position (Integer)

    The beginning index of the substring.

  • length (Integer, nil) (defaults to: nil)

    The desired length of the substring.

Returns:



1152
1153
1154
1155
1156
# File 'lib/ronin/code/sql/functions.rb', line 1152

def substring(string,position,length=nil)
  if length then Function.new(:SUBSTRING,string,position,length)
  else           Function.new(:SUBSTRING,string,position)
  end
end

#substring_index(string, deliminator, count) ⇒ Function

The SUBSTRING_INDEX function.

Parameters:

  • string (Field, Function, Symbol, String)

    The string to search within.

  • deliminator (Field, Function, Symbol, String)

    The deliminator string to search for.

  • count (Integer)

    The number of times to search for the deliminator.

Returns:



1173
1174
1175
# File 'lib/ronin/code/sql/functions.rb', line 1173

def substring_index(string,deliminator,count)
  Function.new(:SUBSTRING_INDEX,string,deliminator,count)
end

#sum(field) ⇒ Function

The SUM function.

Parameters:

  • field (Field, Symbol)

    The field to aggregate.

Returns:



97
98
99
# File 'lib/ronin/code/sql/functions.rb', line 97

def sum(field)
  Function.new(:SUM,field)
end

#tan(x) ⇒ Function

The TAN function.

Parameters:

Returns:



537
538
539
# File 'lib/ronin/code/sql/functions.rb', line 537

def tan(x)
  Function.new(:TAN,x)
end

#trim(string_or_options) ⇒ Function

The TRIM function.

Parameters:

  • string_or_options (String, Hash{Symbol => Object})

Options Hash (string_or_options):

Returns:



1193
1194
1195
# File 'lib/ronin/code/sql/functions.rb', line 1193

def trim(string_or_options)
  Function.new(:TRIM,string_or_options)
end

#truncate(x, d) ⇒ Function

The TRUNCATE function.

Parameters:

Returns:



551
552
553
# File 'lib/ronin/code/sql/functions.rb', line 551

def truncate(x,d)
  Function.new(:TRUNCATE,x,d)
end

#ucase(string) ⇒ Function

The UCASE function.

Parameters:

  • string (Field, Function, Symbol, String)

    The string argument for UCASE.

Returns:



1206
1207
1208
# File 'lib/ronin/code/sql/functions.rb', line 1206

def ucase(string)
  Function.new(:UCASE,string)
end

#unhex(string) ⇒ Function

The UNHEX function.

Parameters:

  • string (Field, Function, Symbol, String)

    The string argument for UNHEX.

Returns:



1219
1220
1221
# File 'lib/ronin/code/sql/functions.rb', line 1219

def unhex(string)
  Function.new(:UNHEX,string)
end

#upper(string) ⇒ Function

The UPPER function.

Parameters:

  • string (Field, Function, Symbol, String)

    The string argument for UPPER.

Returns:



1232
1233
1234
# File 'lib/ronin/code/sql/functions.rb', line 1232

def upper(string)
  Function.new(:UPPER,string)
end