"unsupported format code: 36" in prepared statement with libpq-fe 9.2.5

Поиск
Список
Период
Сортировка
От Raymond C. Rodgers
Тема "unsupported format code: 36" in prepared statement with libpq-fe 9.2.5
Дата
Msg-id 52CEBF77.5030503@gmail.com
обсуждение исходный текст
Ответы Re: "unsupported format code: 36" in prepared statement with libpq-fe 9.2.5  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-interfaces
<font size="-1">Hello,<br /><br /> I haven't been working with libpq-fe for long (only the last month or so) but I've
hadthe good fortune of being able to figure out and solve most problems I've encountered within a few minutes to an
hour,but this one is different. I have a prepared statement that is inserting data into 12 of the 13 columns my table
has(1 UUID, 4 numerics, 1 bigint, 2 ints, 1 boolean, 2 varchars, and 1 of 2 timestamps are being inserted). This is the
firsttime I've attempted to insert more than 8 columns at once, but I'm pretty sure the number of columns isn't the
problemI'm hitting. At least, I don't think it is. Some of the vital details: Fedora 18 (64-bit), PostgreSQL and
libpq-feversion 9.2.5, code written in C++ compiled with gcc version 4.7.2 20121109. The errors are being pulled from
thepg_logs directory for the appropriate day. (I'm using "tail -f" to watch as they occur.)<br /><br /> I've prepared
thestatement with code similar to the following (lines broken up for slight readability improvement); DB is an PGconn
pointerthat has already been connected to the database by this point:<br /><br /> Oid dozenFieldTypes[12] =
{0,0,0,0,0,0,0,0,0,0,0,0};<br/> PQprepare(DB,"insertData","insert into mytable (data1, data2, data3, data4, data5,<br
/>                 data6, data7, data8 ,data9, data10, data11, data12) values ($1, $2::double precision,<br />        
       $3::double precision, $4::double precision, $5::double precision,$6,$7,$8,<br />                
$9::int,$10::int,$11::boolean,$12::timestamp with time zone)",12,dozenFieldType);<br /><br /> The above is how the
querycurrently exists after hours of banging my head on this "unsupported format code: 36" error; I've tried casting
eachfor the inputs as the appropriate type in addition to trying to let PostgreSQL/libpq-fe figure it out completely.
Asyou can see, I'm somewhere in the middle of the two at the moment. Nonetheless, I don't get the error on the creation
ofthe prepared statement, though I am curious if the numbering above 9 for the parameters should be in decimal or
hexadecimal.I've only tried decimal at this point because it seems logical that it would continue in decimal and I've
foundno indications otherwise in the documentation. Of course, I also haven't found anything in the documentation that
statesthat a dozen parameters can be used.<br /><br /> I'm hitting the error when I try to execute the statement using
codesimilar to the following; only my variable and custom function names have been changed:<br /><br />         const
char*value[12];<br />         char dt12[30];<br />         memset(dt12,0,30);<br />    // convert timestamp from time_t
tostring<br />         struct tm time_s;<br />         memset(&time_s,0,sizeof(time_s));<br />        
gmtime_r(&data12,&time_s);<br/>         strftime(dt12,29,"%Y-%m-%d %H:%M:%S GMT",&time_s); <br /><br />    
   int32_t dt9 = bswap_32(data9),dt10 = bswap_32(data10);<br />         int64_t dt6 = bswap_64(atol(data6));<br
/></font><fontsize="-1"><font size="-1">// prepDouble is a custom function to swap bytes appropriately<br /> // for
doubles;proven to work properly elsewhere in code<br /></font>        double dt2 = prepDouble(data2),dt3 = </font><font
size="-1"><fontsize="-1">prepDouble</font>(data3),<br />                  dt4 = </font><font size="-1"><font
size="-1">prepDouble</font>(data4),dt5 = </font><font size="-1"><font size="-1">prepDouble</font>(data5);<br />        
value[0]= data1; // UUID stored as string (char *)<br />         value[1] = (char*)&dt2;<br />         value[2] =
(char*)&dt3;<br/>         value[3] = (char*)&dt4;<br />         value[4] = (char*)&dt5;<br />        
value[5]= (char*)&dt6;<br />         value[6] = data7; //string (char*) taken as is<br />         value[7] = data8;
</font><fontsize="-1"><font size="-1">//string (char*) taken as is<br /></font>        value[8] = (char*)&dt9;<br
/>        value[9] = (char*)&dt10;<br />         const char  *dt11 = (char*)&data11; // boolean tried as int,
string,and in original bool format, made no difference in error<br />         value[10] = dt11;<br />         value[11]
=dt12;<br />          int32_t format[12] = {0,0,0,0,0,0,0,0,0,0,0,0};<br />         int32_t length[12] = {(int32_t)
strlen(data1),sizeof(dt2), sizeof(dt3), sizeof(dt4), sizeof(dt5),<br />                 sizeof(dt6), (int32_t)
strlen(data7),(int32_t) strlen(data8), sizeof(dt9), sizeof(dt10),<br />                 sizeof(data11), (int32_t)
strlen(dt12)};<br/>         PQexecPrepared(DB,"</font><font size="-1"><font
size="-1">insertData</font>",12,value,format,length,1);<br/><br /> Once the PQexecPrepared() has executed, I'm getting
thefollowing in the PostgreSQL log:<br /><br /> ERROR:  unsupported format code: 36<br /> STATEMENT:  insert into
mytable(data1,data2,data3,data4,data5,data6,data7,data8,data9,data10,data11,data12) values ($1,$2::double
precision,$3::doubleprecision,$4::double precision,$5::double
precision,$6,$7,$8,$9::int,$10::int,$11::boolean,$12::timestampwith time zone)<br /><br /> So far, I haven't been able
todetermine precisely what "unsupported format code: 36" refers to. I've tried playing with the resultFormat arameter
inthe PQexecPrepared() call, changing the casting types of just about every data item, and in the case of the boolean,
usingan intermediate variable of a different type and making the conversion, to rule it out. There *are* two data types
thatI haven't tried using in libpq-fe before now, though I'm sure one is fine: UUID (data1) and int64_t/bigint (data6).
I'mpretty sure that the UUID is fine since it's being stored in the program as a simple string (char *) and I got an
errorwhen I adjusted the prepared statement to cast the value as varchar(36). (The error basically said that it was a
UUIDvalue and that I need to change the casting.) Data6, on the other hand, is an unknown factor. While I've been
inserting64-bit data types (doubles) into the database easily enough, this is the first time I've tried working with a
long/int64_t/bigintand the database. I presume that since the bswap_32 from byteswap.h works properly, that it's
siblingbswap_64 is also working properly. As you might notice, data6 is being converted from a string to int64_t via
atol(),and I've checked to make sure that's working properly.<br /><br /> So, that pretty much explains where I am
gettingstuck. I haven't been able to find out what "unsupported format code: 36" is referring to, there doesn't seem to
beany documentation covering that error, and I think I've done all I can to try to resolve it without having good
informationabout what is causing the error.<br /><br /> I'd greatly appreciate any help I can get to resolve this
error,and document it for posterity. :-)<br /><br /> Best regards and thank you,<br /> Raymond <br /></font> 

В списке pgsql-interfaces по дате отправления:

Предыдущее
От: Devrim GÜNDÜZ
Дата:
Сообщение: Re: pgxs installation issue
Следующее
От: Tom Lane
Дата:
Сообщение: Re: "unsupported format code: 36" in prepared statement with libpq-fe 9.2.5