Re: Problem with using snprintf in C-function
От | Tom Lane |
---|---|
Тема | Re: Problem with using snprintf in C-function |
Дата | |
Msg-id | 26492.1255797972@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | Problem with using snprintf in C-function (Ilya Urikh <ilya.urikh@gmail.com>) |
Список | pgsql-general |
Ilya Urikh <ilya.urikh@gmail.com> writes: > This code I wrote for PostgreSQL 8.3.7 on Fedora 10 and it worked fine. But > now I use CentOS 5.3 and PostgreSQL 8.3.8. It looks to me like you're assuming that %ld is the appropriate format string for an int64 value. This might be true on a 64-bit machine but it would not be on 32-bit. It's not obvious why that would lead to exactly the results you show, but it could certainly account for snprintf fetching the wrong bits for some of its arguments. The portable way (within Postgres code) is to use INT64_FORMAT, which will be set up correctly by configure. So instead of > WHERE accountId = %ld AND\ you need WHERE accountId = " INT64_FORMAT " AND\ (relying on concatenation of literals in C). BTW, if your compiler didn't warn you about this, you need to get a new compiler, or at least start using the switches that would make it warn you. If you did get a warning, and ignored it, you need to learn better habits ;-) regards, tom lane
В списке pgsql-general по дате отправления: