-
 Zitat von andreaspr@aon.at
Nur den PATH kann man leider nicht mit Hostvariablen abbilden :-(
Ja das ist schade. Aber es klappt trotzdem grundsätzlich. Der Pfad wird im dynamischen SQL-String angefügt. Mein Problem war dabei das Clob für den JSON-String. Das funktioniert ganz gut mit den Host-Variablen.
Allerdings habe ich leider immer noch ein Problem mit den Zeichensätzen. Ich habe den SQL-String als varucs2 deklariert. Das Parser normaler Zeichenketten klappt sehr gut. Aber sobald ich ein echtes Unicode Zeichen im JSON-String drinhabe, wird nichts mehr geparst. Irgendwie haut das mit den Clobs und Unicode noch nicht so hin.
Die Deklaration dcl-s clobDS sqltype(clob:200000) ccsid(1200); wird vom Compiler nicht akzeptiert. Ich musste den Clob ohne ccsid deklarieren. Ich fürchte, dass da irgendwo das Problem liegt.
Hier mal das ganze Programm, falls es jemanden interessiert:
Code:
//==========================================================================================
// Funktion:
//
// Syntax zum Parsen von JSON mit der JSON_TABLE Funktion:
// $ – Start with the current object
// . – Look inside an object
// [ ] – Look inside an array
// – Reference the value associated with a key
//
//==========================================================================================
dcl-proc um_JSON_getString export;
dcl-pi *n varucs2(200000);
json_in varucs2(200000) const;
path varucs2(1000) const;
end-pi;
dcl-s anw varucs2(16000);
dcl-s json_clobDS sqltype(clob:200000);
dcl-s clobDS sqltype(clob:200000);
json_clobDS_data = %trim(json_in);
json_clobDS_len = %len(%trimr(json_in));
//Jetzt das SQL-Statement zusammenbauen:
anw = 'select inhalt from JSON_TABLE(?, ' + um_hkUni('lax $')
+ ' columns( inhalt clob(200000) path ' + um_hkUni('lax $.' + path) + ')) as json';
exec sql prepare cmd from :anw;
exec sql declare csr1 cursor for cmd;
exec sql open csr1 using :json_clobDS;
UM_JoblogSQL(sqlcod:##PGMNAME:'open');
if sqlcod = 0;
exec sql fetch next from csr1 into :clobDS;
if sqlcod <> 0;
clear clobDS;
UM_JoblogSQL(sqlcod:##PGMNAME:'fetch');
endif;
endif;
exec sql close csr1;
return %ucs2(%trimr(%subst(clobDS_data:1:clobDS_len)));
end-proc;
-
Ich bin eben darauf gestoßen, dass es außer dem sqltype(clob) noch den sqltype(dbclob) also "Double Byte" Clob gibt. Bei diesem Typ kann man auch eine ccsid(1200) angeben. Ich probiere damit mal ein bisschen rum.
-
Solange dein CLOB < 8 mb ist, kannst du ggf. auch eine Hostvariable vom Typ Unicode bis 8MB definieren. Einen CLOB brauchst du da noch nicht.
Ansonsten gibt es da noch den DBCLOB, der nun tatsächlich als Unicode 1200 definiert ist (max. 8 M).
Du kannst also von deinem HTTP-Request den CLOB in DBCLOB aus dem CLOB mit CCSID 1208 casten.
Der Typ der generierten Variablen ist GRAPH und die CCSID dafür bestimmst du in der H-Zeile (Default 1200, früher 13488).
PS:
Da warst du wirklich schneller. Aber eine CCSID kannst du auch hier nicht angeben, da der Default bereits 1200 ist.
-
Vielen Dank. Wenn 1200 der Default Wert ist, werde ich ccsid(1200) weglassen. Macht den Code kürzer.
-
Das Weglassen von ccsid(1200) geht leider doch nicht. Ich bekomme folgenden Fehler bei Kompilieren:
json_clobDS_data = %trim(json_in);
RNF0659: Implizite Zeichenfolgeumsetzung wird für Operand JSON_CLOBDS ... mit CCSID *GRAPH: *IGNORE nicht unterstützt.
Liegt möglicherweise an unseren Compileoptionen. Aber kein Problem. Dann schreibe ich ccsid(1200) halt explizit dran.
-
JSON ist aber per Definition immer UTF-8, das wäre CCSID 1208. Geht die?
-
 Zitat von AG1965_2
JSON ist aber per Definition immer UTF-8, das wäre CCSID 1208. Geht die?
Nein.
Code:
dcl-s json_clobDS sqltype(dbclob:200000) ccsid(1208);
SQL5067 ID des codierten Zeichensatzes (CCSID) 1208 ist für JSON_CLOBDS nicht gültig.
-
Du musst die CCSID für GRAPH in der H-Zeile definieren:
CCSID(*GRAPH : parameter | *UCS2 : number | *CHAR :
*JOBRUN)
CCSID(*GRAPH) and CCSID(*UCS2) set the default graphic (*GRAPH) and UCS-2
(*UCS2) CCSIDs for the module. These defaults are used for literals, compile-time
data, program-described input and output fields, and data definitions that do not
have the CCSID keyword coded.
CCSID(*CHAR) sets the CCSID used for the module’s character data at runtime.
CCSID(*GRAPH : *IGNORE | *SRC | number)
Sets the default graphic CCSID for the module. The possible values are:
*IGNORE
This is the default. No conversions are allowed between graphic and
UCS-2 fields in the module. The %GRAPH built-in function cannot be
used.
*SRC
The graphic CCSID associated with the CCSID of the source file will be
used.
number
A graphic CCSID. A valid graphic CCSID is 65535 or a CCSID with the
EBCDIC double-byte encoding scheme (X’1200’).
CCSID(*UCS2 : number)
Sets the default UCS-2 CCSID for the module. If this keyword is not
specified, the default UCS-2 CCSID is 13488.
number must be a UCS-2 CCSID. A valid UCS-2 CCSID has the UCS-2
encoding scheme (x’7200’). For example, the UTF-16 CCSID 1200 has
encoding scheme x’7200’.
If CCSID(*GRAPH : *SRC) or CCSID(*GRAPH : number) is specified:
v Graphic and UCS-2 fields in externally-described data structures will use the
CCSID in the external file.
v Program-described graphic or UCS-2 fields will default to the graphic or UCS-2
CCSID of the module, respectively. This specification can be overridden by using
the CCSID(number) keyword on the definition of the field. (See “CCSID(number
| *DFT)” on page 325.)
v Program-described graphic or UCS-2 input and output fields and keys are
assumed to have the module’s default CCSID.
CCSID(*CHAR : *JOBRUN)
When CCSID(*CHAR:*JOBRUN) is specified, character data will be
assumed to be in the job CCSID at runtime. The character X’0E’ will be
assumed to be a shift-out character only if the runtime job CCSID is a
mixed-byte CCSID.
Control-Specification Keywords
260 ILE RPG Reference
|
|
#
#
#
When CCSID(*CHAR : *JOBRUN) is not specified, character data will be
assumed to be in the mixed-byte CCSID related to the job CCSID. If the
character X’0E’ appears in character data, it will be interpreted as a
shift-out character. This may cause incorrect results when character data is
converted to UCS-2 data.
Note: Specifying CCSID(*CHAR:*JOBRUN) does not change the behaviour
of the compiler with respect to character literals containing X’0E’.
When a character literal contains X’0E’, the compiler will always
treat it as a shift-out character, independent of the CCSID(*CHAR)
keyword
Also
H CCSID(*GRAPH:1200)
Dann sollte der DBCLOB mit 1200 definiert werden.
Zusätzlich musst du das Ergebnis des HTTP-Requests, das ja vom Typ CLOB ist, in DBCLOB umwandeln:
cast(http..... as DBCLOB(1000000, 1208))
oder
DBCLOB(http....., 1000000, 1208)
Similar Threads
-
By -Totti in forum IBM i Hauptforum
Antworten: 5
Letzter Beitrag: 25-05-18, 20:21
-
By dschroeder in forum NEWSboard Programmierung
Antworten: 20
Letzter Beitrag: 05-12-17, 13:38
-
By tarkusch in forum NEWSboard Programmierung
Antworten: 2
Letzter Beitrag: 05-05-14, 08:57
-
By harbir in forum NEWSboard Programmierung
Antworten: 1
Letzter Beitrag: 31-10-13, 19:10
-
By CMueller@must.de in forum NEWSboard Windows
Antworten: 0
Letzter Beitrag: 01-10-01, 10:00
Berechtigungen
- Neue Themen erstellen: Nein
- Themen beantworten: Nein
- You may not post attachments
- You may not edit your posts
-
Foren-Regeln
|
Erweiterte Foren Suche
Google Foren Suche
Forum & Artikel Update eMail
AS/400 / IBM i
Server Expert Gruppen
Unternehmens IT
|
Kategorien online Artikel
- Big Data, Analytics, BI, MIS
- Cloud, Social Media, Devices
- DMS, Archivierung, Druck
- ERP + Add-ons, Business Software
- Hochverfügbarkeit
- Human Resources, Personal
- IBM Announcements
- IT-Karikaturen
- Leitartikel
- Load`n`go
- Messen, Veranstaltungen
- NEWSolutions Dossiers
- Programmierung
- Security
- Software Development + Change Mgmt.
- Solutions & Provider
- Speicher – Storage
- Strategische Berichte
- Systemmanagement
- Tools, Hot-Tips
Auf dem Laufenden bleiben
|
Bookmarks