(8) Working With Postgre Sql :-
we will talk about :-
PGQuery(Statement)
For example:-
PGRESULT(select_statment).
For example :-
PGDELETE(table_name , column_name , column_value).
(UPDATE 'employees' SET id=2 ,name="Mohannad Aldulaimi" , salary=1700 where id=1)
we will talk about :-
- PGQuery().
- PGadd2db().
- PGresult().
- PGdelete().
- pgupdatedb()
-
(1) Create An Object from Dragon-PostGreSql-Ext in the route.ring file :-
oDPG = new DpG
-
(Or) Use Importlib(cLibName) in manage.ring file to import the lib to
"Batch/ImportedLibs" file then load it in Route.ring file... -
(2) Make Sure To Set This Connection Values Like
oDPG = new DpG oDPG{ pg_username = "postgres" pg_password = " " pg_database = "Dragon_ring" pg_port = "5432" pg_conn = NULL }
PG --> means Postgre Sql
PGQuery(Statement)
This function take one parameter contain sql statement.
PGADD2DB(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 oDPG = new DpG oDPG{ pg_username = "postgres" pg_password = " " pg_database = "Dragon_ring" pg_port = "5432" pg_conn = NULL PGADD2DB('employees(id , name , salary)' , [1, "Mohannad" , 1800] ) }
PGRESULT(select_statment).
For example :-
#!ring -cgi
load 'dragon-ring.ring'
import system.Web
oDPG = new DpG
oDPG{
pg_username = "postgres"
pg_password = " "
pg_database = "Dragon_ring"
pg_port = "5432"
pg_conn = NULL
/* This code has written in route.ring (just for testing) */
res = PGRESULT('SELECT * From employees ;')
for col=1 to len(res)
for row=1 to len(res[col])
html(res[col][row] + TAB)
next
html('<br/>')
next
}
The result is :-
id name salary
1 Mohannad 1800
PGDELETE(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
oDPG = new DpG
oDPG{
pg_username = "postgres"
pg_password = " "
pg_database = "Dragon_ring"
pg_port = "5432"
pg_conn = NULL
/* This code has written in route.ring (just for testing) */
PGDELETE('employees' , 'id' , 1 )
/* This code will delete the id,name,salary from database for the employee id 1 */
}
PGUPDATEDB(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 oDPG = new DpG oDPG{ pg_username = "postgres" pg_password = " " pg_database = "Dragon_ring" pg_port = "5432" pg_conn = NULL /* This code has written in route.ring (just for testing) */ table_columns = [ "id" , "name" , "salary" ] Table_values = [ 2 , "Mohannad Aldulaimi" , 1700] PGUPDATEDB('employees', 'id' , 1 ,table_columns, Table_values) }this function will make a sql statement like this :-
(UPDATE 'employees' SET id=2 ,name="Mohannad Aldulaimi" , salary=1700 where id=1)
I hope it was easy for you ...