Thread: ecpg code wont write to db
hi -- im using ecpg to issue commands to my postgresql db on my school's Solaris system. The commands that read from the db seem to function properly. Those that should write to the db run but have no effect. I have no trouble writing to the db from php code. a small multi-threaded server (written in C, using pthreads) accepts calls on a stream internet socket. The server spawns a thread for each incoming call. The code the thread executes calls a C wrapper for some C++ code; the C++ code calls the C functions which were compiled from the ecpg. This architecture is due to the fact that the C++ code must control the program as a whole. i doubt that the multi-threading is the cause of the problem, as the client (php) makes only a single call each time it is run. a sample of the code follows. i'd very much appreciate any help anyone can give me with this. int do_login(const char *mstsLname, const char *mstsPasswd) { EXEC SQL BEGIN DECLARE SECTION; const char *mstsLogname = mstsLname; const char *mstsPassword = mstsPasswd; int mstsLoginStatus = 0; EXEC SQL END DECLARE SECTION; EXEC SQL WHENEVER NOT FOUND GOTO notfound; connect_to_postgresql(); EXEC SQL SELECT count(*) INTO :mstsLoginStatus FROM ms_account A WHERE A.logname = :mstsLogname AND A.password = :mstsPassword; if (mstsLoginStatus == 1) { EXEC SQL INSERT INTO ms_logInOut (logname, logDate, isIn) VALUES (:mstsLogname, SYSDATE, 'y'); EXEC SQL COMMIT; } disconnect_from_postgresql(); return mstsLoginStatus; /* -1 for error; 0 if no such login; 1 if OK */ notfound: disconnect_from_postgresql_error(); return -1; /* return 'not found' */ }
write to file using ECPGdebug
like
like
ECPGdebug(1, f);
where f is your file pointer.
Include this right in the beginning of your code and then check this file to see where is your ECPG throwing error.
~Jas
On 4/21/07, Andrew Jarcho <ajarcho@nyc.rr.com> wrote:
hi --
im using ecpg to issue commands to my postgresql db on my school's
Solaris system. The commands that read from the db seem to function
properly. Those that should write to the db run but have no effect. I
have no trouble writing to the db from php code.
a small multi-threaded server (written in C, using pthreads) accepts
calls on a stream internet socket. The server spawns a thread for each
incoming call. The code the thread executes calls a C wrapper for some
C++ code; the C++ code calls the C functions which were compiled from
the ecpg. This architecture is due to the fact that the C++ code must
control the program as a whole.
i doubt that the multi-threading is the cause of the problem, as the
client (php) makes only a single call each time it is run.
a sample of the code follows. i'd very much appreciate any help anyone
can give me with this.
int do_login(const char *mstsLname, const char *mstsPasswd)
{
EXEC SQL BEGIN DECLARE SECTION;
const char *mstsLogname = mstsLname;
const char *mstsPassword = mstsPasswd;
int mstsLoginStatus = 0;
EXEC SQL END DECLARE SECTION;
EXEC SQL WHENEVER NOT FOUND GOTO notfound;
connect_to_postgresql();
EXEC SQL
SELECT count(*) INTO :mstsLoginStatus
FROM ms_account A
WHERE A.logname = :mstsLogname AND
A.password = :mstsPassword;
if (mstsLoginStatus == 1) {
EXEC SQL INSERT INTO ms_logInOut (logname, logDate, isIn)
VALUES (:mstsLogname, SYSDATE, 'y');
EXEC SQL COMMIT;
}
disconnect_from_postgresql();
return mstsLoginStatus; /* -1 for error; 0 if no such login; 1 if OK */
notfound:
disconnect_from_postgresql_error();
return -1; /* return 'not found' */
}
---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at
http://www.postgresql.org/about/donate