(9) Working With Sqlite :-
we will talk about :-
  • Query().
  • add2db().
  • result().
  • delete().
  • update()

Connect to Sqlite :

(1) Add This line to Route.ring :-

oDsqlite = new Dsqlite(c_DB_Namae)

(2) You Can Find the db file in folder 'Databases'


After that You Can use this useful functions


Query(Statement)

This function take one parameter contain sql statement.


ADD2DB(Table_name , Table_values).

This function take two parameters as :-

  • Table_name :- the name of the table and tables columns if you want ...
  • Table_values :- list of values you want to add to PostgreSql database .

For example:-

#!ring  -cgi 
load 'dragon-ring.ring'
import system.Web
oDsqlite = new Dsqlite(str2hex('My_test')+'.db')
oDsqlite{
  Query('Create Table Comp(
  emp_id integer,
  emp_name TEXT NOT NULL
  );')	
  add2db('Comp',[1,'Mohannad'])
}

RESULT(select_statment).
For example :-
#!ring  -cgi 
load 'dragon-ring.ring'
import system.Web
oDsqlite = new Dsqlite(str2hex('My_test')+'.db')
oDsqlite{
  res = Result('Select * from comp;')
}

Or
#!ring  -cgi 
load 'dragon-ring.ring'
import system.Web
aResult = []
oDsqlite = new Dsqlite(str2hex('My_test')+'.db')
oDsqlite{
  res = 'Select * from comp;'
  aResult = res
}
The result is :-
      id        name       
      1       Mohannad

DELETE(table_name , column_name , column_value).

This function take three parameters :-

  • table_name :- The name of the table .
  • column_name :- The parimary key column like ( id ) .
  • column_value :- The Value of the parimary key (column_name).
#!ring  -cgi 
load 'dragon-ring.ring'
import system.Web
oDsqlite = new Dsqlite(str2hex('My_test')+'.db')
oDsqlite{
  Delete('comp','id',1)
}
UPDATE(table_name,column_name,column_value,columns_names,columns_values) This function take five parameters :-
  • table_name:- The name of the Table .
  • column_name :- the name of the column you want to update by .
  • column_value :-The Value of (column_name).
  • columns_names :- list of columns that you want to update.
  • columns_values :- list of values that you want to update (depending columns_names)
#!ring  -cgi 
load 'dragon-ring.ring'
import system.Web
oDsqlite = new Dsqlite(str2hex('My_test')+'.db')
oDsqlite{
  Update('comp','id',1,['name'],'Mohannad Al-Dulaimi')
}
this function will make a sql statement like this :-
(UPDATE 'comp' SET name="Mohannad Aldulaimi" where id=1)

I hope it was easy for you ...