SlideShare a Scribd company logo
1 of 10
Download to read offline
Ring Documentation, Release 1.5.2
sinh(0) = 0
sinh(1) = 1.18
cosh(0) = 1
cosh(1) = 1.54
tanh(0) = 0
tanh(1) = 0.76
exp(0) = 1
exp(1) = 2.72
log(1) = 0
log(2) = 0.69
log10(1) = 0
log10(2) = 0.30
log10(10) = 1
Ceil(1.12) = 2
Ceil(1.72) = 2
Floor(1.12) = 1
Floor(1.72) = 1
fabs(1.12) = 1.12
fabs(1.72) = 1.72
pow(2,3) = 8
sqrt(16) = 4
Random number Max (100) : 87
Random number Max (100) : 49
Random number Max (100) : 99
Random number Max (100) : 58
Random number Max (100) : 15
Random number Max (100) : 46
Random number Max (100) : 37
Random number Max (100) : 64
Random number Max (100) : 73
Random number Max (100) : 35
Random number Max (100) : 89
Random number Max (100) : 80
Random number Max (100) : 20
Random number Max (100) : 33
Random number Max (100) : 44
Random number Max (100) : 89
Random number Max (100) : 82
Random number Max (100) : 94
Random number Max (100) : 83
Random number Max (100) : 68
1
1.1
1.12
1.123
1.1235
1.12346
1.123457
1.1234568
1.12345679
1.123456789
1.1234567890
1.12345678901
1.123456789012
1.1234567890123
1.12345678901230
Hash : 3372029979.00000000000000
43.8. Math Class 325
Ring Documentation, Release 1.5.2
43.9 DateTime Class
Methods:
Method Description/Output
clock() The number of clock ticks from program start.
time() Get the system time.
date() Get the date.
timelist() List contains the date and the time information.
adddays(cDate,nDays) Return Date from cDate and after nDays
diffdays(cDate1,cDate2) Return the Number of days (cDate1 - cDate2)
example:
Load "stdlib.ring"
oDateTime = new datetime
See "Test the datetime Class Methods" + nl
See "Calculate performance" + nl
t1 = oDateTime.clock()
for x = 1 to 1000000 next
see oDateTime.clock() - t1 + nl
See "Time : " + oDateTime.time() + nl
See "Date : " + oDateTime.date() + nl
See oDateTime.TimeList()
See "Month Name : " + oDateTime.TimeList()[4]
cDate = oDateTime.date()
see cDate + nl
cDate = oDateTime.adddays(cDate,10)
see cDate + nl
cDate1 = oDateTime.date()
see cDate1 + nl
cDate2 = oDateTime.adddays(cDate1,10)
see cDate2 + nl
see "DiffDays = " + oDateTime.diffdays(cDate1,cDate2) + nl
see "DiffDays = " + oDateTime.diffdays(cDate2,cDate1) + nl
output:
Test the datetime Class Methods
Calculate performance
85
Time : 02:53:35
Date : 31/08/2016
Wed
Wednesday
Aug
August
08/31/16 02:53:35
31
43.9. DateTime Class 326
Ring Documentation, Release 1.5.2
02
02
244
08
53
AM
35
35
3
08/31/16
02:53:35
16
2016
Arab Standard Time
%
Month Name : August31/08/2016
10/09/2016
31/08/2016
10/09/2016
DiffDays = -10
DiffDays = 10
43.10 File Class
Methods:
43.10. File Class 327
Ring Documentation, Release 1.5.2
Method Description/Output
read(cFileName) Read the ļ¬le content
write(cFileName,cStr) Write string to ļ¬le
dir(cFolderPath) Get the folder contents (ļ¬les & sub folders)
rename(cOld,cNew) Rename ļ¬les using the Rename() function
remove(cFileName) Delete a ļ¬le using the Remove() function
open(cFileName,cMode) Open a ļ¬le using the Fopen() function
close() Close ļ¬le
ļ¬‚ush() Flushes the output buffer of a stream
reopen(cFileName,cMode) Open another ļ¬le using the same ļ¬le handle
tempļ¬le() Creates a temp. ļ¬le (binary).
seek(noffset,nwhence) Set the ļ¬le position of the stream
tell() Know the current ļ¬le position of a stream
rewind() Set the ļ¬le position to the beginning of the ļ¬le
getpos() Get handle to the current ļ¬le position
setpos(poshandle) Set the current ļ¬le position
clearerr() Clear the EOF error and the error indicators of a stream
eof() Test the end-of-ļ¬le indicator
error() Test the error indicator
perror(cErrorMessage) Print error message to the stderr
getc() Get the next character from the stream
gets(nsize) Read new line from the stream
putc(cchar) Write a character to the stream
puts(cStr) Write a string to the stream
ungetc(cchar) Push a character to the stream
fread(nsize) Read data from a stream
fwrite(cString) Write data to a stream
exists(cFileName) Check if a ļ¬le exists
example:
Load "stdlib.ring"
ofile = new file
See "Test the file Class Methods" + nl
see ofile.read(filename())
see nl
ofile.open(filename(),"r")
see ofile.gets(100) + nl
ofile.close()
43.11 System Class
Methods:
43.11. System Class 328
Ring Documentation, Release 1.5.2
Method Description/Output
system() Execute system commands
sysget() Get environment variables
ismsdos() Check if the operating system is MSDOS or not
iswindows() Check if the operating system is Windows or not
iswindows64() Check if the operating system is Windows 64bit or not
isunix() Check if the operating system is Unix or not
ismacosx() Check if the operating system is Mac OS X or not
islinux() Check if the operating system is Linux or not
isfreebsd() Check if the operating system is FreeBSD or not
isandroid() Check if the operating system is Android or not
windowsnl() Get the windows new line string
sysargv() Get the command line arguments passed to the ring script
ļ¬lename() Get the active source ļ¬le
example:
Load "stdlib.ring"
oSystem = new System
See "Test the System Class Methods" + nl
oSystem.system("dir")
see oSystem.sysget("path") + nl
see oSystem.ismsdos() + nl
see oSystem.iswindows() + nl
see oSystem.iswindows64() + nl
see oSystem.isunix() + nl
see oSystem.ismacosx() + nl
see oSystem.islinux() + nl
see oSystem.isfreebsd() + nl
see oSystem.isandroid() + nl
see oSystem.windowsnl() + nl
see oSystem.sysargv() + nl
see oSystem.filename() + nl
43.12 Debug Class
Methods:
Method Description/Output
eval(cCode) Execute code during the runtime from string.
raise(cError) Raise an exception.
assert(cCondition) Test condition before executing the code.
example:
Load "stdlib.ring"
oDebug = new Debug
See "Test the Debug Class Methods" + nl
oDebug.eval("see 'Hello'+nl")
try
x = 10
oDebug.assert(x=11)
43.12. Debug Class 329
Ring Documentation, Release 1.5.2
catch see "assert" + nl done
raise("Error!")
43.13 DataType Class
Methods:
Method Description/Output
isstring(vValue) We can know if the value is a string or not.
isnumber(vValue) We can know if the value is a number or not.
islist(vValue) We can know if the value is a list or not.
type(vValue) Know the type of a value
isnull(vValue) Check the value to know if itā€™s null or not.
isalnum(vValue) 1 if the value is digit/letter or 0 if not
isalpha(vValue) 1 if the value is a letter or 0 if not
iscntrl(vValue) 1 if the value is a control character (no printing position)
isdigit(vValue) 1 if the value is a digit or 0 if not
isgraph(vValue) 1 if the value can be printed (Except space) or 0 if not
islower(vValue) 1 if the value is lowercase letter or 0 if not
isprint(vValue) 1 if the value occupies a printing position or 0 if not
ispunct(vValue) 1 if the value is a punctuation character or 0 if not
isspace(vValue) 1 if the value is a white-space or 0 if not
isupper(vValue) 1 if the value is an uppercase alphabetic letter or 0 if not
isxdigit(vValue) 1 if the value is a hexdecimal digit character or 0 if not
example:
Load "stdlib.ring"
oDataType = new DataType
See "Test the DataType Class Methods" + nl
see oDataType.isstring("test") + nl
see oDataType.isnumber(1) + nl
see oDataType.islist(1:3) + nl
see oDataType.type("test") + nl
see oDataType.isnull(null) + nl
see oDataType.isalnum("Hello") + nl + # print 1
oDataType.isalnum("123456") + nl + # print 1
oDataType.isalnum("ABCabc123") + nl + # print 1
oDataType.isalnum("How are you") + nl # print 0 because of spaces
see oDataType.isalpha("Hello") + nl + # print 1
oDataType.isalpha("123456") + nl + # print 0
oDataType.isalpha("ABCabc123") + nl + # print 0
oDataType.isalpha("How are you") + nl # print 0
See oDataType.iscntrl("hello") + nl + # print 0
oDataType.iscntrl(nl) # print 1
see oDataType.isdigit("0123456789") + nl + # print 1
oDataType.isdigit("0123a") + nl
see oDataType.isgraph("abcdef") + nl + # print 1
oDataType.isgraph("abc def") + nl # print 0
see oDataType.islower("abcDEF") + nl + # print 0
oDataType.islower("ghi") + nl # print 1
see oDataType.isprint("Hello") + nl + # print 1
oDataType.isprint("Nice to see you") + nl + # print 1
oDataType.isprint(nl) + nl # print 0
43.13. DataType Class 330
Ring Documentation, Release 1.5.2
see oDataType.isprint("Hello") + nl # print 1
see oDataType.isupper("welcome") + nl + # print 0
oDataType.isupper("WELCOME") + nl # print 1
see oDataType.isxdigit("0123456789abcdef") + nl + # print 1
oDataType.isxdigit("123z") # print 0
Output:
Test the DataType Class Methods
1
1
1
STRING
1
1
1
1
0
1
0
0
0
0
11
0
1
0
0
1
1
1
0
1
0
1
1
0
43.14 Conversion Class
Methods:
Method Description/Output
number(vValue) Convert strings to numbers.
string(vValue) Convert numbers to strings.
ascii(vValue) Get the ASCII code for a letter.
char(vValue) Convert the ASCII code to character.
hex(vValue) Convert decimal to hexadecimal.
dec(vValue) Convert hexadecimal to decimal.
str2hex(vValue) Convert string characters to hexadecimal characters.
hex2str(vValue) Convert hexadecimal characters to string.
example:
Load "stdlib.ring"
43.14. Conversion Class 331
Ring Documentation, Release 1.5.2
oConversion = new conversion
See "Test the conversion Class Methods" + nl
See oConversion.number("3") + 5 + nl
See oConversion.string(3) + "5" + nl
See oConversion.Ascii("m") + nl
See oConversion.char(77) + nl
see oConversion.hex(162) + nl
see oConversion.dec("a2") + nl
cHex = oConversion.str2hex("Hello")
see cHex + nl
see oConversion.hex2str(cHex) + nl
Output:
Test the conversion Class Methods
8
35
109
M
a2
162
48656c6c6f
Hello
43.15 ODBC Class
Methods:
Method Description/Output
drivers() Get a list of ODBC drivers.
datasources() Get a list of ODBC data sources.
close() Free resources.
connect(cConString) Connect to the database.
disconnect() Close the connection.
execute(cSQL) Execute SQL Statements
colcount() Get columns count in the query result
fetch() Fetch a row from the query result
getdata(nCol) Get column value from the fetched row
tables() Get a list of tables inside the database
columns(cTableName) Get a list of columns inside the table
autocommit(lStatus) Enable or disable the auto commit feature
commit() Commit updates to the database
rollback() Rollback updates to the database
example:
Load "stdlib.ring"
oodbc = new odbc
See "Test the odbc Class Methods" + nl
oODBC {
see drivers()
see datasources()
See "Connect to database" + nl
see connect("DBQ=test.mdb;Driver={Microsoft Access Driver (*.mdb)}") + nl
See "Select data" + nl
43.15. ODBC Class 332
Ring Documentation, Release 1.5.2
see execute("select * from person") + nl
nMax = colcount()
See "Columns Count : " + nMax + nl
while fetch()
See "Row data:" + nl
for x = 1 to nMax
see getdata(x) + " - "
next
end
See "Close database..." + nl
disconnect()
close()
}
43.16 MySQL Class
Methods:
Method Description/Output
info() Return string contains the MySQL Client version.
error() Get the error message from the MySQL Client.
connect(cServer,cUser,cPass,cDatabase) Connect to the MySQL database server.
close() Close the connection to the MySQL database.
query(cQuery) Execute SQL queries.
insert_id() Get the inserted row id.
result() Get the query result (data without column names).
next_result() Move to the next query result.
columns() Get a list of columns names.
result2() Get all of the column names then the query result in one list.
escape_string(cStr) Before storing binary data and special characters in the database.
autocommit(lStatus) Enable or disable the auto commit feature.
commit() Commit updates to the database.
rollback() Rollback updates to the database.
example:
Load "stdlib.ring"
omysql = new mysql
See "Test the MySQL Class Methods" + nl
omysql {
see info() + nl
connect("localhost", "root", "root","mahdb")
see "Execute Query" + nl
query("SELECT * FROM Employee")
see "Print Result" + nl
see result2()
see "Close database" + nl
close()
}
Output:
Test the MySQL Class Methods
5.5.30
43.16. MySQL Class 333
Ring Documentation, Release 1.5.2
Execute Query
Print Result
Id
Name
Salary
1
Mahmoud
15000
2
Samir
16000
3
Fayed
17000
Close database
43.17 SQLite Class
Methods:
Method Description/Output
open(cDatabase) Open Database.
close() Close Database.
errormessage() Get Error Message.
execute(cSQL) Execute Query.
example:
Load "stdlib.ring"
osqlite = new sqlite
See "Test the sqlite Class Methods" + nl
osqlite {
open("test.db")
sql = "CREATE TABLE COMPANY(" +
"ID INT PRIMARY KEY NOT NULL," +
"NAME TEXT NOT NULL," +
"AGE INT NOT NULL," +
"ADDRESS CHAR(50)," +
"SALARY REAL );"
execute(sql)
sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " +
"VALUES (1, 'Mahmoud', 29, 'Jeddah', 20000.00 ); " +
"INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " +
"VALUES (2, 'Ahmed', 27, 'Jeddah', 15000.00 ); " +
"INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" +
"VALUES (3, 'Mohammed', 31, 'Egypt', 20000.00 );" +
"INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" +
"VALUES (4, 'Ibrahim', 24, 'Egypt ', 65000.00 );"
execute(sql)
aResult = execute("select * from COMPANY")
for x in aResult
for t in x
43.17. SQLite Class 334

More Related Content

What's hot

What's hot (20)

The Ring programming language version 1.6 book - Part 27 of 189
The Ring programming language version 1.6 book - Part 27 of 189The Ring programming language version 1.6 book - Part 27 of 189
The Ring programming language version 1.6 book - Part 27 of 189
Ā 
The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31
Ā 
The Ring programming language version 1.4 book - Part 8 of 30
The Ring programming language version 1.4 book - Part 8 of 30The Ring programming language version 1.4 book - Part 8 of 30
The Ring programming language version 1.4 book - Part 8 of 30
Ā 
The Ring programming language version 1.5.4 book - Part 30 of 185
The Ring programming language version 1.5.4 book - Part 30 of 185The Ring programming language version 1.5.4 book - Part 30 of 185
The Ring programming language version 1.5.4 book - Part 30 of 185
Ā 
The Ring programming language version 1.10 book - Part 46 of 212
The Ring programming language version 1.10 book - Part 46 of 212The Ring programming language version 1.10 book - Part 46 of 212
The Ring programming language version 1.10 book - Part 46 of 212
Ā 
The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210
Ā 
The Ring programming language version 1.8 book - Part 30 of 202
The Ring programming language version 1.8 book - Part 30 of 202The Ring programming language version 1.8 book - Part 30 of 202
The Ring programming language version 1.8 book - Part 30 of 202
Ā 
The Ring programming language version 1.9 book - Part 32 of 210
The Ring programming language version 1.9 book - Part 32 of 210The Ring programming language version 1.9 book - Part 32 of 210
The Ring programming language version 1.9 book - Part 32 of 210
Ā 
The Ring programming language version 1.5.2 book - Part 29 of 181
The Ring programming language version 1.5.2 book - Part 29 of 181The Ring programming language version 1.5.2 book - Part 29 of 181
The Ring programming language version 1.5.2 book - Part 29 of 181
Ā 
The Ring programming language version 1.2 book - Part 19 of 84
The Ring programming language version 1.2 book - Part 19 of 84The Ring programming language version 1.2 book - Part 19 of 84
The Ring programming language version 1.2 book - Part 19 of 84
Ā 
The Ring programming language version 1.7 book - Part 28 of 196
The Ring programming language version 1.7 book - Part 28 of 196The Ring programming language version 1.7 book - Part 28 of 196
The Ring programming language version 1.7 book - Part 28 of 196
Ā 
The Ring programming language version 1.3 book - Part 21 of 88
The Ring programming language version 1.3 book - Part 21 of 88The Ring programming language version 1.3 book - Part 21 of 88
The Ring programming language version 1.3 book - Part 21 of 88
Ā 
The Ring programming language version 1.5.1 book - Part 23 of 180
The Ring programming language version 1.5.1 book - Part 23 of 180The Ring programming language version 1.5.1 book - Part 23 of 180
The Ring programming language version 1.5.1 book - Part 23 of 180
Ā 
The Ring programming language version 1.8 book - Part 35 of 202
The Ring programming language version 1.8 book - Part 35 of 202The Ring programming language version 1.8 book - Part 35 of 202
The Ring programming language version 1.8 book - Part 35 of 202
Ā 
The Ring programming language version 1.6 book - Part 38 of 189
The Ring programming language version 1.6 book - Part 38 of 189The Ring programming language version 1.6 book - Part 38 of 189
The Ring programming language version 1.6 book - Part 38 of 189
Ā 
The Ring programming language version 1.10 book - Part 39 of 212
The Ring programming language version 1.10 book - Part 39 of 212The Ring programming language version 1.10 book - Part 39 of 212
The Ring programming language version 1.10 book - Part 39 of 212
Ā 
The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196
Ā 
The Ring programming language version 1.3 book - Part 16 of 88
The Ring programming language version 1.3 book - Part 16 of 88The Ring programming language version 1.3 book - Part 16 of 88
The Ring programming language version 1.3 book - Part 16 of 88
Ā 
The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31
Ā 
The Ring programming language version 1.10 book - Part 54 of 212
The Ring programming language version 1.10 book - Part 54 of 212The Ring programming language version 1.10 book - Part 54 of 212
The Ring programming language version 1.10 book - Part 54 of 212
Ā 

Similar to The Ring programming language version 1.5.2 book - Part 36 of 181

Similar to The Ring programming language version 1.5.2 book - Part 36 of 181 (20)

The Ring programming language version 1.5.3 book - Part 37 of 184
The Ring programming language version 1.5.3 book - Part 37 of 184The Ring programming language version 1.5.3 book - Part 37 of 184
The Ring programming language version 1.5.3 book - Part 37 of 184
Ā 
The Ring programming language version 1.5.4 book - Part 25 of 185
The Ring programming language version 1.5.4 book - Part 25 of 185The Ring programming language version 1.5.4 book - Part 25 of 185
The Ring programming language version 1.5.4 book - Part 25 of 185
Ā 
The Ring programming language version 1.2 book - Part 14 of 84
The Ring programming language version 1.2 book - Part 14 of 84The Ring programming language version 1.2 book - Part 14 of 84
The Ring programming language version 1.2 book - Part 14 of 84
Ā 
The Ring programming language version 1.8 book - Part 42 of 202
The Ring programming language version 1.8 book - Part 42 of 202The Ring programming language version 1.8 book - Part 42 of 202
The Ring programming language version 1.8 book - Part 42 of 202
Ā 
The Ring programming language version 1.9 book - Part 45 of 210
The Ring programming language version 1.9 book - Part 45 of 210The Ring programming language version 1.9 book - Part 45 of 210
The Ring programming language version 1.9 book - Part 45 of 210
Ā 
The Ring programming language version 1.5.2 book - Part 24 of 181
The Ring programming language version 1.5.2 book - Part 24 of 181The Ring programming language version 1.5.2 book - Part 24 of 181
The Ring programming language version 1.5.2 book - Part 24 of 181
Ā 
The Ring programming language version 1.5.3 book - Part 36 of 184
The Ring programming language version 1.5.3 book - Part 36 of 184The Ring programming language version 1.5.3 book - Part 36 of 184
The Ring programming language version 1.5.3 book - Part 36 of 184
Ā 
The Ring programming language version 1.5.4 book - Part 36 of 185
The Ring programming language version 1.5.4 book - Part 36 of 185The Ring programming language version 1.5.4 book - Part 36 of 185
The Ring programming language version 1.5.4 book - Part 36 of 185
Ā 
The Ring programming language version 1.5.2 book - Part 35 of 181
The Ring programming language version 1.5.2 book - Part 35 of 181The Ring programming language version 1.5.2 book - Part 35 of 181
The Ring programming language version 1.5.2 book - Part 35 of 181
Ā 
The Ring programming language version 1.2 book - Part 13 of 84
The Ring programming language version 1.2 book - Part 13 of 84The Ring programming language version 1.2 book - Part 13 of 84
The Ring programming language version 1.2 book - Part 13 of 84
Ā 
The Ring programming language version 1.3 book - Part 27 of 88
The Ring programming language version 1.3 book - Part 27 of 88The Ring programming language version 1.3 book - Part 27 of 88
The Ring programming language version 1.3 book - Part 27 of 88
Ā 
The Ring programming language version 1.10 book - Part 33 of 212
The Ring programming language version 1.10 book - Part 33 of 212The Ring programming language version 1.10 book - Part 33 of 212
The Ring programming language version 1.10 book - Part 33 of 212
Ā 
The Ring programming language version 1.7 book - Part 39 of 196
The Ring programming language version 1.7 book - Part 39 of 196The Ring programming language version 1.7 book - Part 39 of 196
The Ring programming language version 1.7 book - Part 39 of 196
Ā 
The Ring programming language version 1.5.1 book - Part 34 of 180
The Ring programming language version 1.5.1 book - Part 34 of 180The Ring programming language version 1.5.1 book - Part 34 of 180
The Ring programming language version 1.5.1 book - Part 34 of 180
Ā 
The Ring programming language version 1.5.3 book - Part 24 of 184
The Ring programming language version 1.5.3 book - Part 24 of 184The Ring programming language version 1.5.3 book - Part 24 of 184
The Ring programming language version 1.5.3 book - Part 24 of 184
Ā 
The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184
Ā 
The Ring programming language version 1.6 book - Part 183 of 189
The Ring programming language version 1.6 book - Part 183 of 189The Ring programming language version 1.6 book - Part 183 of 189
The Ring programming language version 1.6 book - Part 183 of 189
Ā 
The Ring programming language version 1.4 book - Part 10 of 30
The Ring programming language version 1.4 book - Part 10 of 30The Ring programming language version 1.4 book - Part 10 of 30
The Ring programming language version 1.4 book - Part 10 of 30
Ā 
The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181
Ā 
The Ring programming language version 1.2 book - Part 24 of 84
The Ring programming language version 1.2 book - Part 24 of 84The Ring programming language version 1.2 book - Part 24 of 84
The Ring programming language version 1.2 book - Part 24 of 84
Ā 

More from Mahmoud Samir Fayed

More from Mahmoud Samir Fayed (20)

The Ring programming language version 1.10 book - Part 212 of 212
The Ring programming language version 1.10 book - Part 212 of 212The Ring programming language version 1.10 book - Part 212 of 212
The Ring programming language version 1.10 book - Part 212 of 212
Ā 
The Ring programming language version 1.10 book - Part 211 of 212
The Ring programming language version 1.10 book - Part 211 of 212The Ring programming language version 1.10 book - Part 211 of 212
The Ring programming language version 1.10 book - Part 211 of 212
Ā 
The Ring programming language version 1.10 book - Part 210 of 212
The Ring programming language version 1.10 book - Part 210 of 212The Ring programming language version 1.10 book - Part 210 of 212
The Ring programming language version 1.10 book - Part 210 of 212
Ā 
The Ring programming language version 1.10 book - Part 208 of 212
The Ring programming language version 1.10 book - Part 208 of 212The Ring programming language version 1.10 book - Part 208 of 212
The Ring programming language version 1.10 book - Part 208 of 212
Ā 
The Ring programming language version 1.10 book - Part 207 of 212
The Ring programming language version 1.10 book - Part 207 of 212The Ring programming language version 1.10 book - Part 207 of 212
The Ring programming language version 1.10 book - Part 207 of 212
Ā 
The Ring programming language version 1.10 book - Part 205 of 212
The Ring programming language version 1.10 book - Part 205 of 212The Ring programming language version 1.10 book - Part 205 of 212
The Ring programming language version 1.10 book - Part 205 of 212
Ā 
The Ring programming language version 1.10 book - Part 206 of 212
The Ring programming language version 1.10 book - Part 206 of 212The Ring programming language version 1.10 book - Part 206 of 212
The Ring programming language version 1.10 book - Part 206 of 212
Ā 
The Ring programming language version 1.10 book - Part 204 of 212
The Ring programming language version 1.10 book - Part 204 of 212The Ring programming language version 1.10 book - Part 204 of 212
The Ring programming language version 1.10 book - Part 204 of 212
Ā 
The Ring programming language version 1.10 book - Part 203 of 212
The Ring programming language version 1.10 book - Part 203 of 212The Ring programming language version 1.10 book - Part 203 of 212
The Ring programming language version 1.10 book - Part 203 of 212
Ā 
The Ring programming language version 1.10 book - Part 202 of 212
The Ring programming language version 1.10 book - Part 202 of 212The Ring programming language version 1.10 book - Part 202 of 212
The Ring programming language version 1.10 book - Part 202 of 212
Ā 
The Ring programming language version 1.10 book - Part 201 of 212
The Ring programming language version 1.10 book - Part 201 of 212The Ring programming language version 1.10 book - Part 201 of 212
The Ring programming language version 1.10 book - Part 201 of 212
Ā 
The Ring programming language version 1.10 book - Part 200 of 212
The Ring programming language version 1.10 book - Part 200 of 212The Ring programming language version 1.10 book - Part 200 of 212
The Ring programming language version 1.10 book - Part 200 of 212
Ā 
The Ring programming language version 1.10 book - Part 199 of 212
The Ring programming language version 1.10 book - Part 199 of 212The Ring programming language version 1.10 book - Part 199 of 212
The Ring programming language version 1.10 book - Part 199 of 212
Ā 
The Ring programming language version 1.10 book - Part 198 of 212
The Ring programming language version 1.10 book - Part 198 of 212The Ring programming language version 1.10 book - Part 198 of 212
The Ring programming language version 1.10 book - Part 198 of 212
Ā 
The Ring programming language version 1.10 book - Part 197 of 212
The Ring programming language version 1.10 book - Part 197 of 212The Ring programming language version 1.10 book - Part 197 of 212
The Ring programming language version 1.10 book - Part 197 of 212
Ā 
The Ring programming language version 1.10 book - Part 196 of 212
The Ring programming language version 1.10 book - Part 196 of 212The Ring programming language version 1.10 book - Part 196 of 212
The Ring programming language version 1.10 book - Part 196 of 212
Ā 
The Ring programming language version 1.10 book - Part 195 of 212
The Ring programming language version 1.10 book - Part 195 of 212The Ring programming language version 1.10 book - Part 195 of 212
The Ring programming language version 1.10 book - Part 195 of 212
Ā 
The Ring programming language version 1.10 book - Part 194 of 212
The Ring programming language version 1.10 book - Part 194 of 212The Ring programming language version 1.10 book - Part 194 of 212
The Ring programming language version 1.10 book - Part 194 of 212
Ā 
The Ring programming language version 1.10 book - Part 193 of 212
The Ring programming language version 1.10 book - Part 193 of 212The Ring programming language version 1.10 book - Part 193 of 212
The Ring programming language version 1.10 book - Part 193 of 212
Ā 
The Ring programming language version 1.10 book - Part 192 of 212
The Ring programming language version 1.10 book - Part 192 of 212The Ring programming language version 1.10 book - Part 192 of 212
The Ring programming language version 1.10 book - Part 192 of 212
Ā 

Recently uploaded

Recently uploaded (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Ā 
šŸ¬ The future of MySQL is Postgres šŸ˜
šŸ¬  The future of MySQL is Postgres   šŸ˜šŸ¬  The future of MySQL is Postgres   šŸ˜
šŸ¬ The future of MySQL is Postgres šŸ˜
Ā 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
Ā 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
Ā 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
Ā 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Ā 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
Ā 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
Ā 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Ā 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
Ā 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
Ā 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
Ā 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
Ā 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Ā 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Ā 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
Ā 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
Ā 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
Ā 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
Ā 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
Ā 

The Ring programming language version 1.5.2 book - Part 36 of 181

  • 1. Ring Documentation, Release 1.5.2 sinh(0) = 0 sinh(1) = 1.18 cosh(0) = 1 cosh(1) = 1.54 tanh(0) = 0 tanh(1) = 0.76 exp(0) = 1 exp(1) = 2.72 log(1) = 0 log(2) = 0.69 log10(1) = 0 log10(2) = 0.30 log10(10) = 1 Ceil(1.12) = 2 Ceil(1.72) = 2 Floor(1.12) = 1 Floor(1.72) = 1 fabs(1.12) = 1.12 fabs(1.72) = 1.72 pow(2,3) = 8 sqrt(16) = 4 Random number Max (100) : 87 Random number Max (100) : 49 Random number Max (100) : 99 Random number Max (100) : 58 Random number Max (100) : 15 Random number Max (100) : 46 Random number Max (100) : 37 Random number Max (100) : 64 Random number Max (100) : 73 Random number Max (100) : 35 Random number Max (100) : 89 Random number Max (100) : 80 Random number Max (100) : 20 Random number Max (100) : 33 Random number Max (100) : 44 Random number Max (100) : 89 Random number Max (100) : 82 Random number Max (100) : 94 Random number Max (100) : 83 Random number Max (100) : 68 1 1.1 1.12 1.123 1.1235 1.12346 1.123457 1.1234568 1.12345679 1.123456789 1.1234567890 1.12345678901 1.123456789012 1.1234567890123 1.12345678901230 Hash : 3372029979.00000000000000 43.8. Math Class 325
  • 2. Ring Documentation, Release 1.5.2 43.9 DateTime Class Methods: Method Description/Output clock() The number of clock ticks from program start. time() Get the system time. date() Get the date. timelist() List contains the date and the time information. adddays(cDate,nDays) Return Date from cDate and after nDays diffdays(cDate1,cDate2) Return the Number of days (cDate1 - cDate2) example: Load "stdlib.ring" oDateTime = new datetime See "Test the datetime Class Methods" + nl See "Calculate performance" + nl t1 = oDateTime.clock() for x = 1 to 1000000 next see oDateTime.clock() - t1 + nl See "Time : " + oDateTime.time() + nl See "Date : " + oDateTime.date() + nl See oDateTime.TimeList() See "Month Name : " + oDateTime.TimeList()[4] cDate = oDateTime.date() see cDate + nl cDate = oDateTime.adddays(cDate,10) see cDate + nl cDate1 = oDateTime.date() see cDate1 + nl cDate2 = oDateTime.adddays(cDate1,10) see cDate2 + nl see "DiffDays = " + oDateTime.diffdays(cDate1,cDate2) + nl see "DiffDays = " + oDateTime.diffdays(cDate2,cDate1) + nl output: Test the datetime Class Methods Calculate performance 85 Time : 02:53:35 Date : 31/08/2016 Wed Wednesday Aug August 08/31/16 02:53:35 31 43.9. DateTime Class 326
  • 3. Ring Documentation, Release 1.5.2 02 02 244 08 53 AM 35 35 3 08/31/16 02:53:35 16 2016 Arab Standard Time % Month Name : August31/08/2016 10/09/2016 31/08/2016 10/09/2016 DiffDays = -10 DiffDays = 10 43.10 File Class Methods: 43.10. File Class 327
  • 4. Ring Documentation, Release 1.5.2 Method Description/Output read(cFileName) Read the ļ¬le content write(cFileName,cStr) Write string to ļ¬le dir(cFolderPath) Get the folder contents (ļ¬les & sub folders) rename(cOld,cNew) Rename ļ¬les using the Rename() function remove(cFileName) Delete a ļ¬le using the Remove() function open(cFileName,cMode) Open a ļ¬le using the Fopen() function close() Close ļ¬le ļ¬‚ush() Flushes the output buffer of a stream reopen(cFileName,cMode) Open another ļ¬le using the same ļ¬le handle tempļ¬le() Creates a temp. ļ¬le (binary). seek(noffset,nwhence) Set the ļ¬le position of the stream tell() Know the current ļ¬le position of a stream rewind() Set the ļ¬le position to the beginning of the ļ¬le getpos() Get handle to the current ļ¬le position setpos(poshandle) Set the current ļ¬le position clearerr() Clear the EOF error and the error indicators of a stream eof() Test the end-of-ļ¬le indicator error() Test the error indicator perror(cErrorMessage) Print error message to the stderr getc() Get the next character from the stream gets(nsize) Read new line from the stream putc(cchar) Write a character to the stream puts(cStr) Write a string to the stream ungetc(cchar) Push a character to the stream fread(nsize) Read data from a stream fwrite(cString) Write data to a stream exists(cFileName) Check if a ļ¬le exists example: Load "stdlib.ring" ofile = new file See "Test the file Class Methods" + nl see ofile.read(filename()) see nl ofile.open(filename(),"r") see ofile.gets(100) + nl ofile.close() 43.11 System Class Methods: 43.11. System Class 328
  • 5. Ring Documentation, Release 1.5.2 Method Description/Output system() Execute system commands sysget() Get environment variables ismsdos() Check if the operating system is MSDOS or not iswindows() Check if the operating system is Windows or not iswindows64() Check if the operating system is Windows 64bit or not isunix() Check if the operating system is Unix or not ismacosx() Check if the operating system is Mac OS X or not islinux() Check if the operating system is Linux or not isfreebsd() Check if the operating system is FreeBSD or not isandroid() Check if the operating system is Android or not windowsnl() Get the windows new line string sysargv() Get the command line arguments passed to the ring script ļ¬lename() Get the active source ļ¬le example: Load "stdlib.ring" oSystem = new System See "Test the System Class Methods" + nl oSystem.system("dir") see oSystem.sysget("path") + nl see oSystem.ismsdos() + nl see oSystem.iswindows() + nl see oSystem.iswindows64() + nl see oSystem.isunix() + nl see oSystem.ismacosx() + nl see oSystem.islinux() + nl see oSystem.isfreebsd() + nl see oSystem.isandroid() + nl see oSystem.windowsnl() + nl see oSystem.sysargv() + nl see oSystem.filename() + nl 43.12 Debug Class Methods: Method Description/Output eval(cCode) Execute code during the runtime from string. raise(cError) Raise an exception. assert(cCondition) Test condition before executing the code. example: Load "stdlib.ring" oDebug = new Debug See "Test the Debug Class Methods" + nl oDebug.eval("see 'Hello'+nl") try x = 10 oDebug.assert(x=11) 43.12. Debug Class 329
  • 6. Ring Documentation, Release 1.5.2 catch see "assert" + nl done raise("Error!") 43.13 DataType Class Methods: Method Description/Output isstring(vValue) We can know if the value is a string or not. isnumber(vValue) We can know if the value is a number or not. islist(vValue) We can know if the value is a list or not. type(vValue) Know the type of a value isnull(vValue) Check the value to know if itā€™s null or not. isalnum(vValue) 1 if the value is digit/letter or 0 if not isalpha(vValue) 1 if the value is a letter or 0 if not iscntrl(vValue) 1 if the value is a control character (no printing position) isdigit(vValue) 1 if the value is a digit or 0 if not isgraph(vValue) 1 if the value can be printed (Except space) or 0 if not islower(vValue) 1 if the value is lowercase letter or 0 if not isprint(vValue) 1 if the value occupies a printing position or 0 if not ispunct(vValue) 1 if the value is a punctuation character or 0 if not isspace(vValue) 1 if the value is a white-space or 0 if not isupper(vValue) 1 if the value is an uppercase alphabetic letter or 0 if not isxdigit(vValue) 1 if the value is a hexdecimal digit character or 0 if not example: Load "stdlib.ring" oDataType = new DataType See "Test the DataType Class Methods" + nl see oDataType.isstring("test") + nl see oDataType.isnumber(1) + nl see oDataType.islist(1:3) + nl see oDataType.type("test") + nl see oDataType.isnull(null) + nl see oDataType.isalnum("Hello") + nl + # print 1 oDataType.isalnum("123456") + nl + # print 1 oDataType.isalnum("ABCabc123") + nl + # print 1 oDataType.isalnum("How are you") + nl # print 0 because of spaces see oDataType.isalpha("Hello") + nl + # print 1 oDataType.isalpha("123456") + nl + # print 0 oDataType.isalpha("ABCabc123") + nl + # print 0 oDataType.isalpha("How are you") + nl # print 0 See oDataType.iscntrl("hello") + nl + # print 0 oDataType.iscntrl(nl) # print 1 see oDataType.isdigit("0123456789") + nl + # print 1 oDataType.isdigit("0123a") + nl see oDataType.isgraph("abcdef") + nl + # print 1 oDataType.isgraph("abc def") + nl # print 0 see oDataType.islower("abcDEF") + nl + # print 0 oDataType.islower("ghi") + nl # print 1 see oDataType.isprint("Hello") + nl + # print 1 oDataType.isprint("Nice to see you") + nl + # print 1 oDataType.isprint(nl) + nl # print 0 43.13. DataType Class 330
  • 7. Ring Documentation, Release 1.5.2 see oDataType.isprint("Hello") + nl # print 1 see oDataType.isupper("welcome") + nl + # print 0 oDataType.isupper("WELCOME") + nl # print 1 see oDataType.isxdigit("0123456789abcdef") + nl + # print 1 oDataType.isxdigit("123z") # print 0 Output: Test the DataType Class Methods 1 1 1 STRING 1 1 1 1 0 1 0 0 0 0 11 0 1 0 0 1 1 1 0 1 0 1 1 0 43.14 Conversion Class Methods: Method Description/Output number(vValue) Convert strings to numbers. string(vValue) Convert numbers to strings. ascii(vValue) Get the ASCII code for a letter. char(vValue) Convert the ASCII code to character. hex(vValue) Convert decimal to hexadecimal. dec(vValue) Convert hexadecimal to decimal. str2hex(vValue) Convert string characters to hexadecimal characters. hex2str(vValue) Convert hexadecimal characters to string. example: Load "stdlib.ring" 43.14. Conversion Class 331
  • 8. Ring Documentation, Release 1.5.2 oConversion = new conversion See "Test the conversion Class Methods" + nl See oConversion.number("3") + 5 + nl See oConversion.string(3) + "5" + nl See oConversion.Ascii("m") + nl See oConversion.char(77) + nl see oConversion.hex(162) + nl see oConversion.dec("a2") + nl cHex = oConversion.str2hex("Hello") see cHex + nl see oConversion.hex2str(cHex) + nl Output: Test the conversion Class Methods 8 35 109 M a2 162 48656c6c6f Hello 43.15 ODBC Class Methods: Method Description/Output drivers() Get a list of ODBC drivers. datasources() Get a list of ODBC data sources. close() Free resources. connect(cConString) Connect to the database. disconnect() Close the connection. execute(cSQL) Execute SQL Statements colcount() Get columns count in the query result fetch() Fetch a row from the query result getdata(nCol) Get column value from the fetched row tables() Get a list of tables inside the database columns(cTableName) Get a list of columns inside the table autocommit(lStatus) Enable or disable the auto commit feature commit() Commit updates to the database rollback() Rollback updates to the database example: Load "stdlib.ring" oodbc = new odbc See "Test the odbc Class Methods" + nl oODBC { see drivers() see datasources() See "Connect to database" + nl see connect("DBQ=test.mdb;Driver={Microsoft Access Driver (*.mdb)}") + nl See "Select data" + nl 43.15. ODBC Class 332
  • 9. Ring Documentation, Release 1.5.2 see execute("select * from person") + nl nMax = colcount() See "Columns Count : " + nMax + nl while fetch() See "Row data:" + nl for x = 1 to nMax see getdata(x) + " - " next end See "Close database..." + nl disconnect() close() } 43.16 MySQL Class Methods: Method Description/Output info() Return string contains the MySQL Client version. error() Get the error message from the MySQL Client. connect(cServer,cUser,cPass,cDatabase) Connect to the MySQL database server. close() Close the connection to the MySQL database. query(cQuery) Execute SQL queries. insert_id() Get the inserted row id. result() Get the query result (data without column names). next_result() Move to the next query result. columns() Get a list of columns names. result2() Get all of the column names then the query result in one list. escape_string(cStr) Before storing binary data and special characters in the database. autocommit(lStatus) Enable or disable the auto commit feature. commit() Commit updates to the database. rollback() Rollback updates to the database. example: Load "stdlib.ring" omysql = new mysql See "Test the MySQL Class Methods" + nl omysql { see info() + nl connect("localhost", "root", "root","mahdb") see "Execute Query" + nl query("SELECT * FROM Employee") see "Print Result" + nl see result2() see "Close database" + nl close() } Output: Test the MySQL Class Methods 5.5.30 43.16. MySQL Class 333
  • 10. Ring Documentation, Release 1.5.2 Execute Query Print Result Id Name Salary 1 Mahmoud 15000 2 Samir 16000 3 Fayed 17000 Close database 43.17 SQLite Class Methods: Method Description/Output open(cDatabase) Open Database. close() Close Database. errormessage() Get Error Message. execute(cSQL) Execute Query. example: Load "stdlib.ring" osqlite = new sqlite See "Test the sqlite Class Methods" + nl osqlite { open("test.db") sql = "CREATE TABLE COMPANY(" + "ID INT PRIMARY KEY NOT NULL," + "NAME TEXT NOT NULL," + "AGE INT NOT NULL," + "ADDRESS CHAR(50)," + "SALARY REAL );" execute(sql) sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " + "VALUES (1, 'Mahmoud', 29, 'Jeddah', 20000.00 ); " + "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " + "VALUES (2, 'Ahmed', 27, 'Jeddah', 15000.00 ); " + "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" + "VALUES (3, 'Mohammed', 31, 'Egypt', 20000.00 );" + "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" + "VALUES (4, 'Ibrahim', 24, 'Egypt ', 65000.00 );" execute(sql) aResult = execute("select * from COMPANY") for x in aResult for t in x 43.17. SQLite Class 334