Module: Ronin::SQL::Functions

Included in:
Clause, InjectionExpr, StatementList
Defined in:
lib/ronin/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.

Returns:



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

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

#acos(x) ⇒ Function

The ACOS function.

Returns:



148
149
150
# File 'lib/ronin/sql/functions.rb', line 148

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

#ascii(string) ⇒ Function

The ASCII function.

Returns:



494
495
496
# File 'lib/ronin/sql/functions.rb', line 494

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

#asin(x) ⇒ Function

The ASIN function.

Returns:



158
159
160
# File 'lib/ronin/sql/functions.rb', line 158

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

#atan(x) ⇒ Function

The ATAN function.

Returns:



168
169
170
# File 'lib/ronin/sql/functions.rb', line 168

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

#atan2(y, x) ⇒ Function

The ATAN2 function.

Returns:



178
179
180
# File 'lib/ronin/sql/functions.rb', line 178

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:



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

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

#bin(n) ⇒ Function

The BIN function.

Returns:



504
505
506
# File 'lib/ronin/sql/functions.rb', line 504

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

#bit_and(x) ⇒ Function

The BIT_AND function.

Returns:



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

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

#bit_count(x) ⇒ Function

The BIT_COUNT function.

Returns:



198
199
200
# File 'lib/ronin/sql/functions.rb', line 198

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

#bit_length(string) ⇒ Function

The BIT_LENGTH function.

Returns:



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

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

#bit_or(x) ⇒ Function

The BIT_OR function.

Returns:



208
209
210
# File 'lib/ronin/sql/functions.rb', line 208

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

#ceil(x) ⇒ Function

The CEIL function.

Returns:



218
219
220
# File 'lib/ronin/sql/functions.rb', line 218

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

#ceiling(x) ⇒ Function

The CEILING function.

Returns:



228
229
230
# File 'lib/ronin/sql/functions.rb', line 228

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

#char(*bytes) ⇒ Function

The CHAR function.

Returns:



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

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

#char_length(string) ⇒ Function

The CHAR_LENGTH function.

Returns:



534
535
536
# File 'lib/ronin/sql/functions.rb', line 534

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

#character_length(string) ⇒ Function

The CHARACTER_LENGTH function.

Returns:



544
545
546
# File 'lib/ronin/sql/functions.rb', line 544

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

#concat(*strings) ⇒ Function

The CONCAT function.

Returns:



554
555
556
# File 'lib/ronin/sql/functions.rb', line 554

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

#concat_ws(separator, *strings) ⇒ Function

The CONCAT_WS function.

Returns:



564
565
566
# File 'lib/ronin/sql/functions.rb', line 564

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

#conv(n, from_base, to_base) ⇒ Function

The CONV function.

Returns:



574
575
576
# File 'lib/ronin/sql/functions.rb', line 574

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

#cos(x) ⇒ Function

The COS function.

Returns:



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

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

#cot(x) ⇒ Function

The COT function.

Returns:



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

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:



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

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

#degrees(x) ⇒ Function

The DEGREES function.

Returns:



258
259
260
# File 'lib/ronin/sql/functions.rb', line 258

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

#elt(n, *strings) ⇒ Function

The ELT function.

Returns:



584
585
586
# File 'lib/ronin/sql/functions.rb', line 584

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

#exp(x) ⇒ Function

The EXP function.

Returns:



268
269
270
# File 'lib/ronin/sql/functions.rb', line 268

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

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

The EXPORT_SET function.

Returns:



594
595
596
597
598
599
600
601
602
# File 'lib/ronin/sql/functions.rb', line 594

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.

Returns:



610
611
612
# File 'lib/ronin/sql/functions.rb', line 610

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

#find_in_set(string, *set) ⇒ Function

The FIND_IN_SET function.

Returns:



620
621
622
# File 'lib/ronin/sql/functions.rb', line 620

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

#floor(x) ⇒ Function

The FLOOR function.

Returns:



278
279
280
# File 'lib/ronin/sql/functions.rb', line 278

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

#format(x, d) ⇒ Function

The FORMAT function.

Returns:



288
289
290
# File 'lib/ronin/sql/functions.rb', line 288

def format(x,d)
  Function.new(:FORMAT,x,d)
end

#glob(x, y) ⇒ Function

The GLOB function.

Returns:



630
631
632
# File 'lib/ronin/sql/functions.rb', line 630

def glob(x,y)
  Function.new(:GLOB,x,y)
end

#greatest(*values) ⇒ Function

The GREATEST function.

Returns:



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

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

#hex(value) ⇒ Function

The HEX function.

Returns:



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

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

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

The INSERT function.

Returns:



650
651
652
# File 'lib/ronin/sql/functions.rb', line 650

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

#instr(string, sub_string) ⇒ Function

The INSTR function.

Returns:



660
661
662
# File 'lib/ronin/sql/functions.rb', line 660

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

#interval(*values) ⇒ Function

The INTERVAL function.

Returns:



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

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

#lcase(string) ⇒ Function

The LCASE function.

Returns:



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

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

#least(*values) ⇒ Function

The LEAST function.

Returns:



318
319
320
# File 'lib/ronin/sql/functions.rb', line 318

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

#left(string, length) ⇒ Function

The LEFT function.

Returns:



680
681
682
# File 'lib/ronin/sql/functions.rb', line 680

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

#length(string) ⇒ Function

The LENGTH function.

Returns:



690
691
692
# File 'lib/ronin/sql/functions.rb', line 690

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

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

The LIKE function.

Returns:



700
701
702
703
704
# File 'lib/ronin/sql/functions.rb', line 700

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.

Returns:



712
713
714
# File 'lib/ronin/sql/functions.rb', line 712

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

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

The LOCATE function.

Returns:



722
723
724
725
726
# File 'lib/ronin/sql/functions.rb', line 722

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

#log(*b, x) ⇒ Function

The LOG function.

Returns:



328
329
330
# File 'lib/ronin/sql/functions.rb', line 328

def log(*b,x)
  Function.new(:LOG,*b,x)
end

#log10(x) ⇒ Function

The LOG10 function.

Returns:



338
339
340
# File 'lib/ronin/sql/functions.rb', line 338

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

#lower(string) ⇒ Function

The LOWER function.

Returns:



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

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

#lpad(string, length, pad_string) ⇒ Function

The LPAD function.

Returns:



744
745
746
# File 'lib/ronin/sql/functions.rb', line 744

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

#ltrim(string) ⇒ Function

The LTRIM function.

Returns:



754
755
756
# File 'lib/ronin/sql/functions.rb', line 754

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

#make_set(bits, *strings) ⇒ Function

The MAKE_SET function.

Returns:



764
765
766
# File 'lib/ronin/sql/functions.rb', line 764

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:



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

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

#mid(string, position, length) ⇒ Function

The MID function.

Returns:



774
775
776
# File 'lib/ronin/sql/functions.rb', line 774

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:



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

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

#mod(n, m) ⇒ Function

The MOD function.

Returns:



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

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

#oct(n) ⇒ Function

The OCT function.

Returns:



784
785
786
# File 'lib/ronin/sql/functions.rb', line 784

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

#octet_length(string) ⇒ Function

The OCTET_LENGTH function.

Returns:



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

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

#ord(string) ⇒ Function

The ORD function.

Returns:



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

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

#piFunction

The PI function.

Returns:



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

def pi
  Function.new(:PI)
end

#position(expr) ⇒ Function

The POSITION function.

Returns:



814
815
816
# File 'lib/ronin/sql/functions.rb', line 814

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

#pow(x, y) ⇒ Function

The POW function.

Returns:



368
369
370
# File 'lib/ronin/sql/functions.rb', line 368

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

#power(x, y) ⇒ Function

The POWER function.

Returns:



378
379
380
# File 'lib/ronin/sql/functions.rb', line 378

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

#quote(string) ⇒ Function

The QUOTE function.

Returns:



824
825
826
# File 'lib/ronin/sql/functions.rb', line 824

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

#radians(x) ⇒ Function

The RADIANS function.

Returns:



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

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

#rand(field) ⇒ Function

The RAND function.

Parameters:

  • field (Field, Symbol)

    The field to aggregate.

Returns:



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

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

#randomFunction

The RANDOM function.

Returns:



398
399
400
# File 'lib/ronin/sql/functions.rb', line 398

def random
  Function.new(:RANDOM)
end

#repeat(string, count) ⇒ Function

The REPEAT function.

Returns:



834
835
836
# File 'lib/ronin/sql/functions.rb', line 834

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

#replace(string, from_string, to_string) ⇒ Function

The REPLACE function.

Returns:



844
845
846
# File 'lib/ronin/sql/functions.rb', line 844

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

#reverse(string) ⇒ Function

The REVERSE function.

Returns:



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

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

#right(string, length) ⇒ Function

The RIGHT function.

Returns:



864
865
866
# File 'lib/ronin/sql/functions.rb', line 864

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

#round(x, d = nil) ⇒ Function

The ROUND function.

Returns:



408
409
410
411
412
# File 'lib/ronin/sql/functions.rb', line 408

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.

Returns:



874
875
876
# File 'lib/ronin/sql/functions.rb', line 874

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

#rtrim(string) ⇒ Function

The RTRIM function.

Returns:



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

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

#sign(x) ⇒ Function

The SIGN function.

Returns:



420
421
422
# File 'lib/ronin/sql/functions.rb', line 420

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

#sin(x) ⇒ Function

The SIN function.

Returns:



430
431
432
# File 'lib/ronin/sql/functions.rb', line 430

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

#soundex(string) ⇒ Function

The SOUNDEX function.

Returns:



894
895
896
# File 'lib/ronin/sql/functions.rb', line 894

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

#space(n) ⇒ Function

The SPACE function.

Returns:



904
905
906
# File 'lib/ronin/sql/functions.rb', line 904

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

#sqrt(x) ⇒ Function

The SQRT function.

Returns:



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

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

#std(field) ⇒ Function

The STD function.

Returns:



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

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

#stddev(field) ⇒ Function

The STDDEV function.

Returns:



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

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

#strcmp(string1, string2) ⇒ Function

The STRCMP function.

Returns:



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

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

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

The SUBSTRING function.

Returns:



924
925
926
927
928
# File 'lib/ronin/sql/functions.rb', line 924

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.

Returns:



936
937
938
# File 'lib/ronin/sql/functions.rb', line 936

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:



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

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

#tan(x) ⇒ Function

The TAN function.

Returns:



470
471
472
# File 'lib/ronin/sql/functions.rb', line 470

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

#trim(string_or_options) ⇒ Function

The TRIM function.

Parameters:

  • string_or_options (String, Hash)

Options Hash (string_or_options):

Returns:



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

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

#truncate(x, d) ⇒ Function

The TRUNCATE function.

Returns:



480
481
482
# File 'lib/ronin/sql/functions.rb', line 480

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

#ucase(string) ⇒ Function

The UCASE function.

Returns:



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

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

#unhex(string) ⇒ Function

The UNHEX function.

Returns:



976
977
978
# File 'lib/ronin/sql/functions.rb', line 976

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

#upper(string) ⇒ Function

The UPPER function.

Returns:



986
987
988
# File 'lib/ronin/sql/functions.rb', line 986

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