Thread: libpq library

libpq library

From
"Familia Cerezo"
Date:
Estimated sirs:
 
    I am a Computers Engineering student. Currently I am doing a program in C which uses the PostgreSQL's library "libpq" and I have a problem:
 
    I can't introduce in the data base a simple quote. For example:
 
    char *sent_sql;
    char *dato;
    strcpy(dato, "grocery's");
    sprintf(sent_sql, "insert into table values ('%s')", dato);
 
    However, I don't have problems with the SQL interpreter, eg.:
        insert into table values ('grocery\'s');
    In this case, the data will be stored as "grocery's" (OK!), but I don't find the way I could do that using the library.
 
    I just can't introduce the '\' character previous to the simple quote because I will loose the final character of the string. I can't define the field as type text because I need that the field had a defined size (I got to store encrypted data).
 
    If you know a solution, I would thank you.
 
    Sorry for my english and thanks for paying attention to this e-mail,
 
                        DAVID.