version 2004
PGSQL_Execute (connID; sqlQuery) Longint
| Parameter | Type | Description | |
| connID | Longint | Connection ID returned by PGSQL_Connect | |
| sqlQuery | Text | SQL statement | |
| Function result | Longint | Result ID |
Description
The PGSQL_Execute command executes the SQL statement and returns a result ID (Longint) that is used with all commands that works on the query result.
connID is a Longint that corresponds to the connection ID returned by PGSQL_Connect.
sqlQuery is a Text parameter that contains the SQL statement you want to execute.
Examples
(1) Inserting a record
`Connection
PGConnID:=PGSQL_Connect($Host;$Port;$Options;$Tty;$Database;$User;$Password)
If(PGConnID#0)
$Query:="INSERT INTO clients (id_clt, name_clt, email_clt, country_clt) VALUES "
$resID:=PGSQL_Execute(PGConnID;$Query)
If($resID#0)
`Get our Execute result status
$rsError:=PGSQL_GetResultStatus($resID;$resultStatus)
`We are performing an INSERT, so we are waiting for a PGRES_COMMAND_OK result status
If($resultStatus="PGRES_COMMAND_OK")
`Our INSERT has been executed
Else
`We didn't get the expected result status
ALERT($resultStatus)
End if
PGSQL_CloseResult($resID)
Else
`$resID is null, we have a result error
ALERT ("null result pointer")
End if
PGSQL_Close(PGConnID)
Else
ALERT(PGSQL_GetLastConnError(PGConnID))
End if
(2) Executing a SELECT
` Connection
PGConnID:=PGSQL_Connect($Host;$Port;$Options;$Tty;$Database;$User;$Password)
If(PGConnID#0)
$Query:="SELECT id_clt, name_clt, email_clt, country_clt FROM clients"
$resID:=PGSQL_Execute(PGConnID;$Query)
If($resID#0)
` Get our Execute result status
$rsError:=PGSQL_GetResultStatus($resID;$resultStatus)
` We are performing a SELECT, so we are waiting for a PGRES_TUPLES_OK result status
If($resultStatus="PGRES_TUPLES_OK")
` Our SELECT has been executed
` Populate Results
$err:=PGSQL_GetRowCount($resID;$nbRows)
For($r;0;$nbRows-1)
$NewPos:=Size of array(ArrLON_ClientID)+1
$err:=PGSQL_GetLongintValue($resID;0;$r;$id_clt)
INSERT ELEMENT(arrLON_ClientID;$NewPos;1)
arrLON_ClientID{$NewPos}:=$id_clt
$err:=PGSQL_GetStringValue($resID;1;$r;$name_clt)
INSERT ELEMENT(arrSTR_Name;$NewPos;1)
arrSTR_Name{$NewPos}:=$name_clt
$err:=PGSQL_GetStringValue($resID;2;$r;$email_clt)
INSERT ELEMENT (arrSTR_Email;$NewPos;1)
arrSTR_Email{$NewPos}:=$email_clt
$err:=PGSQL_GetStringValue($resID;3;$r;$country_clt)
INSERT ELEMENT (arrSTR_Country;$NewPos;1)
arrSTR_Country{$NewPos}:=$country_clt
End for
Else
`We didn't get the expected result status
`Catch error here
End if
PGSQL_CloseResult($resID)
Else
`$resID is null, we have a result error
`Catch error here
End if
PGSQL_Close(PGConnID)
Else
`PGConnID is null, we have a connection error
ALERT(PGSQL_GetLastConnError(PGConnID))
End if