PDA

View Full Version : SQL Reset Cursor



camouflage
28-05-20, 16:06
Hallo Forum,

Folgende Aufgabenstellung:
Ich habe eine Inbox und möchte mit einem NEP prüfen, ob irgendwelche Files angekommen sind.

Dazu habe ich folgende Definition:


exec SQL declare C1 scroll cursor for
select file
from table(rtvdir(:myPath))
where file like '%.txt'
for read only;

Klappt auch hervorragend. Nur wenn ich ein weiteres File in's Verzeichnis ablege, keine Reaktion. Natürlich kann ich den Reset mittels Close/Open forcieren. Nur geht es auch ohne?
p.s. Den Fetch habe ich mit first und next probiert.

ExAzubi
29-05-20, 06:39
Nein, leider nicht, das ein SELECT eine Momentaufnahem der Tabelle ist....
So kann es dir auf DB-Tabellen passieren, das du Datensätze verarbeitest, die schon gar nicht mehr in der Tabelle sind.

Fuerchau
29-05-20, 08:31
"Scroll Cursor" besagt ja nur, dass du nach vorne rollen kannst.
Was dir fehlt ist "sensitive".
Ob dies allerdings auch mit Table-Functions funktioniert glaube ich nicht, da du die Sensitivität nicht an die Table-Function weiterleiten kannst.

Zumal man noch bedenken muss, dass Table-Functions häufig von API's o.ä. abhängen, die sowieso nicht sensitive sind.

@ExAzubi
Der Cursor ist im Gegensatz zu z.B. SQL-Server keine Momentafnahme.
Andere DB's arbeiten da z.B. mit Table-Locks oder Satzversionen um insensitive Daten zu garantieren.

ASENSITIVE, SENSITIVE, or INSENSITIVE
Specifies whether the cursor is asensitive, sensitive, or insensitive to changes. If
statement-name is specified, the default is the corresponding prepare attribute of
the statement. Otherwise, ASENSITIVE is the default.
ASENSITIVE
Specifies that the cursor may behave as SENSITIVE or INSENSITIVE
depending on how the select-statement is optimized.
SENSITIVE
Specifies that changes made to the database after the cursor is opened are
visible in the result table. The cursor has some level of sensitivity to any
updates or deletes made to the rows underlying its result table after the
cursor is opened. The cursor is always sensitive to positioned updates or
deletes using the same cursor. Additionally, the cursor can have sensitivity
to changes made outside this cursor. If the database manager cannot make
changes visible to the cursor, then an error is returned. The database
manager cannot make changes visible to the cursor when the cursor
implicitly becomes read-only. (See Result table of a cursor.) If SENSITIVE is
specified, the SELECT statement cannot contain a data-change-table-reference.
INSENSITIVE
Specifies that once the cursor is opened, it does not have sensitivity to
inserts, updates, or deletes performed by this or any other activation
group. If INSENSITIVE is specified, the cursor is read-only and a
temporary result is created when the cursor is opened. In addition, the
SELECT statement cannot contain a UPDATE clause and the application
must allow a copy of the data (ALWCPYDTA(*OPTIMIZE) or
ALWCPYDTA(*YES)).

Nur wenn der Cursor explizit als INSENSITIVE erstellt wird und die Daten temporär kopiert werden dürfen hast du deine Momentaufnahme.

BenderD
29-05-20, 12:03
... dieser ganze Murks ist doch nix anderes als dspxxx output(*OUTFILE) in eine UDTF verpackt, damit es modern aussieht, erkauft mit mieser Ergonomie und mieser Performance. Da kannst Du drin rumscrollen, wie Du willst, das ist dem Snapshot in der QTEMP doch völlig Wurscht. Natürlich könnte man das auch ordentlich machen, aber wo IBM draufsteht ist schon lange nicht mehr drin, für was IBM und AS/400 früher legendär war...

D*B

camouflage
29-05-20, 13:59
@Baldur
... sensitive bin höchstens ich, aber der entsprechende scroll überhaupt nichts (ja, ich habs auch versucht) gebracht. Also ab in die Tonne - bleibt halt nichts anderes übrig open/close. Das funktioniert.

@Dieter
... da geb ich dir schon recht. Gerade heute hat mir der data-gen OP-Code (auch wenn Barbara Morris dahinter steckt) schon mal einige graue Haare mehr beschert. Nein, Du musst es nicht kommentieren!

BenderD
29-05-20, 14:42
... dieses HKG Prinzip ist eh nix Gescheites, wenn man das schon nicht von Grund auf vorwärts designed (Objekt ablegen, Event hinterherschicken) machen will...
Seit wann und für was gibt es eigentlich STRJRN??? Einfach mal den command prompten, ist ja keine UDTF!

D*B