How can we get database name in progress openedge like in SQL we can get database name by using show databases; or SELECT schema_name FROM information_schema.schemata; using SQL query to openedge DB.
In ABL you can
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DO i = 1 TO NUM-DBS:
MESSAGE LDBNAME (i) SKIP
PDBNAME (i) SKIP
DBPARAM (i)
VIEW-AS ALERT-BOX INFORMATION BUTTONS OK.
END.
In OpenEdge SQL the SHOW CATALOGS command returns the database/catalog names:
https://docs.progress.com/bundle/openedge-sql-reference/page/SHOW-CATALOGS.html?_ga=2.234385114.558448476.1620632697-128156788.1596090319
SHOW CATALOGS PRO_NAME;
select db_name() from sysprogress.syscalctable;
Just in case the link to "Progress Communities" goes away:
Valeriy Bashkatov (Progress Technologies LLC)
You should run this with a DBA privileged user.
select * from sysprogress.SYSTABLES;
select * from sysprogress.SYSTABLES_FULL;
select * from sysprogress.SYSCOLUMNS where TBL = 'table_name';
select * from sysprogress.SYSCOLUMNS_FULL where TBL = 'table_name';
Related
I want to create a browse such that it will show all the records from one table if the values of a field do NOT exist in another table.
It is possible to get the records using SQL as:
SELECT myField FROM pub.myTable WHERE
NOT EXISTS (SELECT myField FROM pub.myTable2 WHERE myTable2.myField=myTable.myField)
It is also possible using 4GL as:
FOR EACH myTable WHERE
NOT CAN-FIND(FIRST myTable2 WHERE myTable2.myField=myTable.myField)
The problem is when I put this query in a browse as:
OPEN QUERY myBrowse
FOR EACH myTable WHERE
NOT CAN-FIND(FIRST myTable2 WHERE myTable2.myField=myTable.myField)
it gives an error message
CAN-FIND is invalid within an OPEN QUERY. (3541)
The question is, is it possible to write such an OPEN QUERY statement?
I didn't come up with this, Steve Moore shared it on https://community-archive.progress.com/forums/00026/27143.html
define temp-table ttNoOrder
field field1 as char.
create ttNoOrder.
define query q1 for Customer, Order, ttNoOrder.
open query q1 for each Customer no-lock,
first Order of Customer outer-join no-lock,
first ttNoOrder where not available(Order).
get first q1.
repeat while not query-off-end("q1"):
display Customer.CustNum Customer.Name available(Order).
get next q1.
end.
Works even with dynamic queries:
DEFINE TEMP-TABLE ttNoOrder
FIELD field1 AS CHARACTER .
DEFINE VARIABLE hQuery AS HANDLE NO-UNDO.
CREATE ttNoOrder.
CREATE QUERY hQuery .
hQuery:SET-BUFFERS (BUFFER Customer:HANDLE,
BUFFER Order:HANDLE,
BUFFER ttNoOrder:HANDLE) .
hQuery:QUERY-PREPARE ("for each Customer no-lock, ~
first Order of Customer outer-join no-lock, ~
first ttNoOrder where not available(Order)") .
hQuery:QUERY-OPEN() .
hQuery:GET-FIRST () .
REPEAT WHILE NOT hQuery:QUERY-OFF-END:
DISPLAY Customer.CustNum FORMAT ">>>>>>>>>9" Customer.Name AVAILABLE(Order).
hQuery:GET-NEXT ().
END.
I have an Access database table named Receipts with the following field names: receipt number item name, buying price, selling price. I am using an Adoquery and datasource to connect to the access database. The following is the code I am using to print a report.
procedure TReceiptsform.BitBtn1Click(Sender: TObject);
var
qry :string;
begin
with ADOQuery1 do
begin
if ADOQuery1.Locate('receipt number',Edit1.Text,[]) then
open;
SQL.Clear;
qry:= 'SELECT*from Receipts WHERE (((Receipts.[receipt number])='+ edit1.Text+'))order by Receipts.[Item name]';
SQL.Add(qry);
Active:= True;
ReceiptForm.QuickRep1.Preview;
end;
end;
However when I run the program then I click BitBtn1Click at runtime, I get this error.
ProjectSales.exe raised exception class EOleException with message 'Extra ) in query expression "(((Receipt.[item name])=))". Process stopped. Use Step or Run to continue.
Which exception handling code can I use to prevent this error or is there a problem with the Query?
You problem is, that if Edit1 is Null, no value is given to filter on because the use of + eliminates the quotes:
'SELECT * from Receipts WHERE (((Receipts.[receipt number])='+ edit1.Text+'))order by Receipts.[Item name]'
=>
'SELECT * from Receipts WHERE (((Receipts.[receipt number])=)) order by Receipts.[Item name]'
So, use ampersand and some spaces:
'SELECT * from Receipts WHERE (((Receipts.[receipt number])=' & edit1.Text &')) order by Receipts.[Item name]'
I have a installation script in which I am trying to create multiple views based on tables from a remote database. The script will be executed on multiple databases, each with their own remote database. Rather than creating multiple versions of the script, I aim to have remote db link as an input parameter prompted during installation. However when i execute the installation script, the first view fails with ORA-02019 while the remaining views are created successfully.
Sample Test version:
install.sql
Set serveroutput on
SET VERIFY OFF
Alter Session Set current_schema = TEST;
SET VERIFY ON
DEFINE DB_LINK = &&db_link
PROMP Install started ...
#./SCRIPTS/views.sql
PROMP Install ended
quit
#./SCRIPTS/views.sql
--View1
Create or replace View tmp_cards as Select nvl((select count(*) from auths#&db_link where cardid = t.id),0) cnt_auths,t.* From Cards#&db_link t ;
--View2
Create or replace View tmp_Auth as Select * From auths#&db_link;
Installation logs
IMPLUSER#db01 SQL>#install.sql
Session altered.
Enter value for db_link: db02
Install started ...
old 1: Create or replace View tmp_cards as Select nvl((select count(*) from auths#&db_link where cardid = t.id),0) cnt_auths,t.* From Cards#&db_link t
new 1: Create or replace View tmp_cards as Select nvl((select count(*) from auths#db02 where cardid = t.id),0) cnt_auths,t.* From Cards#db02 t
Create or replace View tmp_cards as Select nvl((select count(*) from auths#db02 where cardid = t.id),0) cnt_auths,t.* From Cards#db02 t
*
ERROR at line 1:
ORA-02019: connection description for remote database not found
old 1: Create or replace View tmp_Auth as Select * From auths#&db_link
new 1: Create or replace View tmp_Auth as Select * From auths#db02
View created.
Install ended
if i create the view directly via command window in PL/SQL, the first view is created successfully
SQL> Create or replace View tmp_cards as Select nvl((select count(*) from auths#db02 where I002_NUMBER = t.cardnumber),0) cnt_auths,t.* From Cards#db02 t;
View created
SQL>
What am I missing?
I have a remote table with blob column accessed via a db link. I want to insert a blob from my local table to remote table blob column.I am executing dynamic sql like follows
declare
theblob blob;
theclob clob;
thenumber number;
begin
select base64encode2(image) into theclob from per_images where image_id = 113077;
execute immediate 'insert into image#APPSERP2ERPAPPS(column1,column2,column3) values((select null from dual),(select base64encode2(image) from per_images where image_id = 113077),(select ceil(5.4) from dual))';
commit;
end;
When i run the sql i get ORA-02069: global_names parameter must be set to TRUE for this operation.
If i do ALTER SESSION SET GLOBAL_NAMES = true then i get database link APPSERP2ERPAPPS.CSN.EDU.PK connects to TEST.CSN.EDU.PK error while inserting into blob.
Kindly tell me how can i insert blob into remote table blob column.
Thanks
To be able to insert over a dblink the insert sentence must match this format
Insert into table2#dblink select * from Table1
here more info.
How to handle a missing feature of SQLite: disable triggers?
I don't have it stored the name of triggers for a specific table.
For example how can I drop all triggers?
What would you do?
So here it is 2015 and there still is no 'disable triggers' in SQLite. For a mobile Application this can be problematic--especially if it's a corporate App requiring offline functionality and local data.
An initial data load can be slowed to crawl by trigger execution even when you don't wrap each insert in an individual transaction.
I solved this issue using SQLite SQL fairly simply. I have a settings table that doesn't participate in the init load. It holds 'list' of key/value pairs. I have one key called 'fireTrigger' with a bit value of 0 or 1. Every trigger I have has an expression that selects value and if it equals 1 it fires the trigger, otherwise it doesn't.
This expression is in addition to any expressions evaluated on the data relating to the trigger. e.g.:
AND 1 = (SELECT val FROM MTSSettings WHERE key = 'fireTrigger')
In simple clean effect this allows me to disable/enable the trigger with a simple UPDATE to the settings table
I wrote a very simple extension function to set a boolean value to true or false.
And a function to retrieve this value (GetAllTriggersOn()).
With this function I can define all my triggers like:
CREATE TRIGGER tr_table1_update AFTER UPDATE ON TABLE1 WHEN GetAllTriggersOn()
BEGIN
-- ...
END
SQLite stores schema (meta) information in the built-in sqlite_master table.
To get a list of available triggers use the below query:
SELECT name FROM sqlite_master
WHERE type = 'trigger' -- AND tbl_name = 'a_table_name'
Set a flag in your database and use it in the triggers WHEN condition.
Say you want to create a trigger on the "clients" table after an insert. You have created a table "trigger_settings" with a TINYINT "triggers_on" field - this is your flag. Then you can set the field to 0 if you want to turn off the filters and to 1 when you want to turn them back on.
Then you create your filter with a WHEN condition that checks the "triggers_on" field.
For example:
CREATE TRIGGER IF NOT EXISTS log_client_data_after_insert
AFTER INSERT
ON [clients]
WHEN (SELECT triggers_on FROM trigger_settings)=1
BEGIN
your_statement
END;
Maybe you can make a stored procedures for droping and creating them. Is that good for you ?
Expanding on Nick Dandoulakis's answer, you could drop all relevant triggers and then reinstate them before the transaction's completion:
BEGIN;
SELECT name, sql FROM sqlite_master WHERE type = 'trigger' AND tbl_name = 'mytable';
-- store all results
-- for each name: DROP TRIGGER $name;
-- do normal work
-- for each sql: execute the SQL verbatim
COMMIT;
Expanding other answers this is how i'm doing it. Take into account that this is disabling all triggers for all tables in the database except some of then used by spatialite
SQLITE_FILE=/tmp/my.sqlite
# Define output sql files as variables
CREATE_TRIGGER_SQL=/tmp/create_triggers.sql
DROP_TRIGGER_SQL=/tmp/drop_triggers.sql
## Dump CREATE TRIGGER statements to a file ##
# To wrap statements in a transaction
echo -e "BEGIN;\n\n" > "${CREATE_TRIGGER_SQL}"
# `SELECT sql` does not output semicolons, so we must concatenate them
sqlite3 -bail "${SQLITE_FILE}" "SELECT sql || ';' FROM sqlite_master WHERE type = 'trigger' AND (name NOT LIKE 'gid_%' AND name NOT LIKE 'ggi_%' AND name NOT LIKE 'ggu_%' AND name NOT LIKE 'gii_%' AND name NOT LIKE 'giu_%' AND name NOT LIKE 'vwgcau_%' AND name NOT LIKE 'vtgcau_%' AND name NOT LIKE 'gcau_%' AND name NOT LIKE 'geometry_columns_%' AND name NOT LIKE 'gcfi_%' AND name NOT LIKE 'gctm_%' AND name NOT LIKE 'vtgcfi_%' AND name NOT LIKE 'vwgcfi_%' AND name NOT LIKE 'vtgcs_%' AND name NOT LIKE 'vwgc_%' AND name NOT LIKE 'vtgc_%' AND name NOT LIKE 'gcs_%');" >> "${CREATE_TRIGGER_SQL}"
echo -e "\n\nCOMMIT;" >> "${CREATE_TRIGGER_SQL}"
## Dump DROP TRIGGER statements to a file ##
echo -e "BEGIN;\n\n" > "${DROP_TRIGGER_SQL}"
sqlite3 -bail "${SQLITE_FILE}" "SELECT 'DROP TRIGGER ' || name || ';' FROM sqlite_master WHERE type = 'trigger' AND (name NOT LIKE 'gid_%' AND name NOT LIKE 'ggi_%' AND name NOT LIKE 'ggu_%' AND name NOT LIKE 'gii_%' AND name NOT LIKE 'giu_%' AND name NOT LIKE 'vwgcau_%' AND name NOT LIKE 'vtgcau_%' AND name NOT LIKE 'gcau_%' AND name NOT LIKE 'geometry_columns_%' AND name NOT LIKE 'gcfi_%' AND name NOT LIKE 'gctm_%' AND name NOT LIKE 'vtgcfi_%' AND name NOT LIKE 'vwgcfi_%' AND name NOT LIKE 'vtgcs_%' AND name NOT LIKE 'vwgc_%' AND name NOT LIKE 'vtgc_%' AND name NOT LIKE 'gcs_%');" >> "${DROP_TRIGGER_SQL}"
echo -e "\n\nCOMMIT;" >> "${DROP_TRIGGER_SQL}"
## Execute like ##
sqlite3 -bail /"${SQLITE_FILE}" < "${DROP_TRIGGER_SQL}"
# do things
sqlite3 -bail /"${SQLITE_FILE}" < "${CREATE_TRIGGER_SQL}"