Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iSErG-0001TO-UG for pgsql-general@arkaria.postgresql.org; Wed, 06 Nov 2019 06:31:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iSErE-0006Mj-JX for pgsql-general@arkaria.postgresql.org; Wed, 06 Nov 2019 06:31:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iSErE-0006Mc-AJ for pgsql-general@lists.postgresql.org; Wed, 06 Nov 2019 06:31:56 +0000 Received: from ms-10.1blu.de ([178.254.4.101]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iSErB-0000qI-6Q for pgsql-general@lists.postgresql.org; Wed, 06 Nov 2019 06:31:55 +0000 Received: from [188.174.81.7] (helo=localhost.unixarea.de) by ms-10.1blu.de with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.86_2) (envelope-from ) id 1iSEr9-0005qy-HJ for pgsql-general@lists.postgresql.org; Wed, 06 Nov 2019 07:31:51 +0100 Received: from localhost.my.domain (localhost [127.0.0.1]) by localhost.unixarea.de (8.15.2/8.14.9) with ESMTPS id xA66Vn3S003334 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO) for ; Wed, 6 Nov 2019 07:31:50 +0100 (CET) (envelope-from guru@unixarea.de) Received: (from guru@localhost) by localhost.my.domain (8.15.2/8.14.9/Submit) id xA66Vn37003333 for pgsql-general@lists.postgresql.org; Wed, 6 Nov 2019 07:31:49 +0100 (CET) (envelope-from guru@unixarea.de) X-Authentication-Warning: localhost.my.domain: guru set sender to guru@unixarea.de using -f Date: Wed, 6 Nov 2019 07:31:49 +0100 From: Matthias Apitz To: pgsql-general@lists.postgresql.org Subject: PostgreSQL && data types in ESQL/C Message-ID: <20191106063149.GA3053@c720-r342378> Reply-To: Matthias Apitz MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="LZvS9be/3tNcYl/X" Content-Disposition: inline X-Operating-System: FreeBSD 13.0-CURRENT r342378 (amd64) X-message-flag: Mails containing HTML will not be read! Please send only plain text. User-Agent: Mutt/1.11.1 (2018-12-01) X-Con-Id: 51246 X-Con-U: 0-guru X-Originating-IP: 188.174.81.7 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --LZvS9be/3tNcYl/X Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello, On our project roadmap to port our LMS (Library Management System) from Sybase/Oracle to PostgreSQL we are now in the phase of addressing the ESQL/C and C++ code parts (some million lines of code). I wrote a small ESQL/C test code to see how the various data types are handled. In general: Is there any good manual about ESQL/C in PostgreSQL? Because, even if there are standards any implementation has its details. In detail: I've created a table with the most used data types: $ cat mytypes.sql create table mytypes ( myint integer, mychar char (4), mydate date, myvchar varchar(81), myblob bytea ) ; and have loaded a row with some data which is shown in pgsql as: $ printf "select * from mytypes;\n" | psql -Usisis -d newsisis myint | mychar | mydate | myvchar | myblob -------+--------+------------+--------------+------------------------------= ------------------------ 1 | char | 08.05.1945 | =D0=BE=D1=81=D0=B2=D0=BE=D0=B1=D0=BE=D0=B6= =D0=B4=D0=B5=D0=BD=D0=B8=D0=B5 | \xd0bed181d0b2d0bed0b1d0bed0b6d0b4d0b5d0bd= d0b8d0b50a (1 Zeile) in the ESQL/C code the host variables are declared as: EXEC SQL BEGIN DECLARE SECTION; ... int myint; char mychar[8]; char mydate[10+1]; char myvchar[81]; char myblob[1024]; ... EXEC SQL END DECLARE SECTION; and the FETCH into these is done with: EXEC SQL FETCH IN c_statename INTO :myint, :mychar, :mydate, :myvch= ar, :myblob; which gives with an ESQL/C test pgm which prints the above host variables: $ /usr/local/sisis-pap/pgsql/bin/ecpg embedded.pgc $ gcc -m64 -o embedded embedded.c -I/usr/local/sisis-pap/pgsql/include -L/u= sr/local/sisis-pap/pgsql/lib/ -lpq -lecpg $ ./embedded stmt: SELECT myint, mychar, mydate, myvchar, myblob FROM mytypes; myint [1] mychar [char] mydate [08.05.1945] myvchar [=D0=BE=D1=81=D0=B2=D0=BE=D0=B1=D0=BE=D0=B6=D0=B4=D0=B5=D0=BD=D0=B8= =D0=B5] myblob [\xd0bed181d0b2d0bed0b1d0bed0b6d0b4d0b5d0bdd0b8d0b50a] It seems(!): - an int appears as binary integer - all others types (even the column type 'date') appear as C type char* - 'date', 'char' and 'varchar' are delivered as '\0' terminated strings - 'bytea' appears as '\0' terminated string coded in hex with "\x" in front Our DBCALL layer must convert these char strings in the data form the application layer is expecting, for example a BLOB ('bytea') into a C struct struct { long blobLength; char blobBytes[MAX_EXPECTED_BLOB]; } blob; For example Sybase handles 'date' and 'bytea' in another way: 'date' is a struct of two long and for 'bytea' an additional host variable for the length must be used in FETCH, INSERT, ... The above is a bit by try and error. Is there any good manual which describes the ESQL/C details for PostgreSQL. Thanks matthias --=20 Matthias Apitz, =E2=9C=89 guru@unixarea.de, http://www.unixarea.de/ +49-176= -38902045 Public GnuPG key: http://www.unixarea.de/key.pub "Glaube wenig, hinterfrage alles, denke selbst: Wie man Manipulationen durc= hschaut" "Believe little, scrutinise all, think by your own: How see through manipul= ations" ISBN-10: 386489218X --LZvS9be/3tNcYl/X Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEXmn7rBYYViyzy/vBR8z35Hb+nREFAl3CaNIACgkQR8z35Hb+ nRF8fw//XqK5NAOebi3zpdQteJ/pGgascE5M4xBpcis8CVqX8iGpaeWaTbQHP867 F7w6G+6vN8wBUjEXRrqIiR/KR3vYJhc5MI23DWyBshomd64P02LPgbxhQGzZm/XD M2S40QXJsKWWV4chZ8WCuKs1vqt1fqsoUjXp5DX+XymUkrrUBkmaBQCTmrfvuKY6 1VWpJ55AUp3aUF6I3HpSJkGyyNKhqMcyoh6JUB/6BdV115w89ged55bUal/aE9K5 NPl/kqpB9N4+bBrleJWl3EockEvjLsoDl7kLOB2fdX0i2SSxMguBts0xIkzQ5336 4owoLOjkHwitpjO0TyYiqqibS65xtMO7lwckiQ+4ntCnoFPB/4y0Lo1PlQ9G5Y4x GOAHQhjzoHhnam9KEiYHBPy2d4QYpJRxCxBZUbVrnFANGsVU+SDZABk4ApR7PH+K PYNnVjt2QZjv/MoF3WxFGeP3tS1+xRovlZLej6YcPvWjMs/aF9oXxgOgPAYPq0bN CYnhmczE8NT18zY018P6i49OQzk6OXsknuQbqTP3QzdNZsR8fw3UemylPJga1QuB Jgmc6X+GkIovPKLIL9CBj/R8S3QmHmB0lT37KU7gUywnmz1c5EYK8BFXu547L3Sh gYCF8DviAuYjS5eM6gH77VYc5hcOe2b6dAgCQMe4iqAIn1D19fQ= =pLVG -----END PGP SIGNATURE----- --LZvS9be/3tNcYl/X--