Clear displayed data with default frame in Progress OpenEdge - openedge

I'm trying to find a way to clear displayed data from the screen before return to the calling procedure.
For example:
FIND FIRST table NO-LOCK NO-ERROR.
DISPLAY table WITH 1 COLUMN.
/* data gets displayed */
PAUSE.
Now how do I clear it before returning to the calling procedure?

To make it easy for yourself your should actually ALWAYS name your frames. Otherwise you will run into problems sooner or later. I will let examples below reflect both named and unnamed frames.
You clear it:
FIND FIRST tablename NO-LOCK NO-ERROR.
DISPLAY tablename WITH 1 COLUMN.
PAUSE.
CLEAR.
PAUSE.
You can also pinpoint a frame to clear:
FIND FIRST tablename NO-LOCK NO-ERROR.
DISPLAY tablename WITH FRAME x1 1 COLUMN.
PAUSE.
CLEAR FRAME x1.
PAUSE.
Or if clearing is not really what you want but rather removing (or actually hiding) the entire frame:
FIND FIRST tablename NO-LOCK NO-ERROR.
DISPLAY tablename WITH FRAME x1 1 COLUMN.
PAUSE.
HIDE FRAME x1.
PAUSE.
You can also hide without pinpointing a frame:
FIND FIRST tablename NO-LOCK NO-ERROR.
DISPLAY tablename.
PAUSE.
HIDE.
PAUSE.

Related

For Each ,For First

What is the meaning of For each and For First.. Example below
FOR EACH <db> NO-LOCK,
FIRST <db> OF <db> NO-LOCK:
DISPLAY ..
Also why we need to use NO-LOCK for every table for every time.
Let's answer by giving an example based on the Progress demo DB:
FOR EACH Customer WHERE Customer.Country = "USA" NO-LOCK,
FIRST Salesrep WHERE Salesrep.salesrep = Customer.Saleserp:
/* your code block */
END.
The FOR EACH Block is an iterating block (loop) that integrates data access (and a few more features like error handling and frame scoping if you want to go that far back).
So the code in "your code block" is executed for every Customer record matching the criteria and it also fetches the matching Salesrep records. The join between Customer and Salesrep is an inner join. So you'll only be processing Customers where the Salesrep exists as well.
FOR statement documentation (includes EACH and FIRST keywords)
NO-LOCK documentation
Google is your friend and documentation on packages is usually quite user-friendly.
Try not to ask questions that can be solved by simple search on StackOverflow.
FOR EACH table
Selects a set of records and starts a block to process those records.
NO-LOCK means what it says, the records are retrieved from the database without any record locking. So you might get a "dirty read" (uncommitted data) and someone else might change the data while you are looking at that record.
That sounds awful but, in reality, NO-LOCK reads are almost always what you want to use. If you do need to update a NO-LOCK record you can just FIND CURRENT with a lock.
FOR EACH NO-LOCK can return large numbers of records in a single network message whereas the other lock types are one record at a time - this makes NO-LOCK quite a bit faster for many purposes. And even without the performance argument you probably don't want to be taking out large numbers of locks and preventing other users running inquiries all the time.
Your example lacks a WHERE clause so, by default, every record in the table is returned using the primary index. If you specify a WHERE clause you will potentially only have a subset of the data to loop through and the index selection may be impacted. You can also add a lot of other options like BY to specify sort order.
FOR FIRST is somewhat similar to FOR EACH except that you only return, at most, a single record. Even if the WHERE clause is empty or would otherwise specify a larger result set. BUT BE CAREFUL - the "FIRST" is deceptive. Even if you specify a sort order using BY the rule is "selection, then sorting". At most only one record gets selected so the BY doesn't matter. The index dictated by the WHERE (or lack of a WHERE) determines the sort order. So if your request something like:
FOR FIRST customer NO-LOCK BY discount:
DISPLAY custNum name discount.
END.
You will fetch customer #1, not customer #41 as you might have expected. (Try the code above with the sports2000 database. Replace FIRST with EACH in a second run.)
FOR EACH table1 NO-LOCK,
FIRST table2 NO-LOCK OF table1:
or
FOR EACH customer NO-LOCK,
FIRST salesRep NO-LOCK OF customer:
DISPLAY custnum name customer.salesRep.
END.
Is a join. The OF is a shortcut telling the compiler to find fields that the two tables have in common to build an implied WHERE clause from. This is one of those "makes a nice demo" features that you don't want to use in real code. It obfuscates the relationship between the tables and makes your code much harder to follow. Don't do that. Instead write out the complete WHERE clause. Perhaps like this:
for each customer no-lock,
first salesRep no-lock where sakesRep.salesRep = customer.salesRep:
display custnum name customer.salesRep.
end.

create empty row in dbgrid

I wanted to insert several lines to database using DBGrid.
on my query, I selected for example:
select * from cust where id='0';
that code will return no record at all so my dbgrid will not show anything but an empty row. Now I wanted to put in data in empty row with new data. However my data needs 2 lines from dbgrid. I wanted dbgrid creates an empty row right after I fill last column in first row. How do I code that? (without inserting the first row data because later I'll insert everything with a seperated button).
thanks!
you can add records in your table with NULLin each column.
For example, suppose the table where the DBGrid is binded to has 4 columns, than you can try this code to add empty records
Query1.InsertRecord([null, null, null, null]);
With this code you can add as many empty records as you like in the DBGrid
That is assuming that the query component you are using supports the InsertRecord method...

Not understanding cursor

The problem i'm dealing with is follow :
I have a table students with name and surname. I create a new table Students2, and i want to fill this table with names and surnames from the first table with cursor.
I make the declare of the cursor, the select part, but in the LOOP PART, i don't understand how you fetch the values. For example, if I do:
FETCH name_surname INTO Students2.name,Students2.surname
it doesn't work, and I don't know how to fix it.
In name_surname I mention, I Selected the name and surname from the first table.
"Declare cursor c1 is select * from student2;
Begin
For i in c1 loop
Dbms_output.put_line(i.fname||','||i.lanme);
End loop;
End;"

how to turn off sequence generation in oracle 11g

Does the sequence number get generated again when DML statements are executed?? i have the scenario that two tables say ID1,date1,name 1 in table1 and ID2,ID1,date2 in table 2. both ID1,and ID2 are generated by sequence. when i update the table 2,the ID1 gets changed but the sequence number in table 1 remains the same.I have inserted the ID1 into table 2, still the update is changing the sequence number in table 2 but its either not reflecting back in table 1. Can some one kindly help me out to update the table 2, without changing the sequence number which was generated and inserted into table 2.
Sequence properties are quite simple.
New sequence number is generated every time when you call nextval function. If you inserting a row in a table, new number is generated once per row. For example, you have new sequence:
insert into my_table (num_field) values (my_sequence.nextval);
You will get 1 in num_field.
For query
insert into my_table (num_field1, num_field2)
values (my_sequence.nextval, my_sequence.nextval);
You will get 1 in BOTH fields.
If you use INSERT .. SELECT my_sequence.nextval ... statement, you will get as many new values as many rows SELECT statement returns.
If you call nextval many times in a row of SELECT statement, you will get ONLY ONE new value per row.
You can use sequence only in a top level SELECT.
To know values that was inserted, use sequence_name.currval function or RETURNING statement:
insert ...
select ...
from ...
returning <field for sequence>
All of that could be used in both SQL and PL/SQL.
That's all what you need to know about sequences.
P. S. I didn't understand your question, but I'm sure, you can solve all your problems now.

Getting a range of tuples from an ordered SQLite table

First I'd like to apologize if the topic seems vague; I always have a hard time framing them succinctly. That done, I'll get into it.
Suppose I have a database table that looks like the following:
CREATE TABLE The_table(
item_id INTEGER PRIMARY KEY ASC AUTOINCREMENT,
item TEXT);
Now, I have a pretty basic query that will get items from said table and order them:
SELECT *
FROM The_table
ORDER BY x;
where x could be either item_id or item. I can guarantee that both fields are order-able. My question is this:
Is there a way to modify the query I gave to get a range of the ordered elements: say from 20th element in the table to the 40th element in the table (after the table has been ordered) or something similar.
Any help would be appreciated.
Thanks,
Yes - it's called "between"
SELECT *
FROM The_Table
WHERE item_id BETWEEN 20 AND 40
This does exactly what it says - it looks for a value between the two numbers supplied. Very useful for finding ranges; works in reverse too (i.e. NOT BETWEEN). For more see here.
If you want a specific row or group of rows (as your updated question suggests) after sorting you can use the LIMIT clause to select a range of entries
SELECT *
FROM The_Table
LIMIT 20, 20
Using LIMIT this way the first number is the starting point in the table and the second number is how many records to return from that point. This statement will return 20 rows starting at row 20 whatever that value is.

Resources