Re: [NOVICE] DB insert Error - Mailing list pgsql-general

From Jasbinder Bali
Subject Re: [NOVICE] DB insert Error
Date
Msg-id a47902760608161311r2c6cf432ld39fcdef3ce1c6b6@mail.gmail.com
Whole thread Raw
In response to Re: [NOVICE] DB insert Error  (Michael Fuhr <mike@fuhr.org>)
Responses Re: [NOVICE] DB insert Error  (Michael Fuhr <mike@fuhr.org>)
List pgsql-general

I'm sending u the main() function that has the ECPG Insert statement and commit in it.

-------------------------------------------START-----------------------------------------------------------
#include < stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>

EXEC SQL INCLUDE sqlca;

#define MP 10
#define MSG_LEN 1024000
#define FLD_LEN 512

char *msg_parts[MP], *msg_header[MP], *msg_body[MP];
char headers[MSG_LEN]="", body[MSG_LEN]="";
char mime_version[FLD_LEN]="", content_type[FLD_LEN]="", content_id[FLD_LEN]="";
char content_description[FLD_LEN]="", content_transfer_encoding[FLD_LEN]="";
char content_length[FLD_LEN]="",content_disposition[FLD_LEN]="";
int part_num=0;
int pnum=0;

char *dst;

int main(int argc, char *argv[])
  {

ECPGdebug (1, stderr);

EXEC SQL CONNECT TO tcp:postgresql://192.168.0.110/xyz USER jsbali;

printf("sql code is %d \n",SQLCODE);
    void split_head_from_body(char *ch, char *o_headers, char *o_body);
    void limit_fields(char *instr, char *outstr, char *fieldname);
    void unlimit_fields(char *instr, char *outstr, char *fieldname);
    void parts(char *intype, char *bdy, char *inbody, int pcount);

    FILE   *fp;

EXEC SQL BEGIN DECLARE SECTION;
    char ch[MSG_LEN];
EXEC SQL END DECLARE SECTION;
 

  int  i,j;
    int  lines;
    unsigned int len;
    char from[FLD_LEN]="", to[FLD_LEN]="", subject[FLD_LEN]="", date[FLD_LEN]="";
    char mesid[FLD_LEN]="", sender[FLD_LEN]="", cc[FLD_LEN]="", bcc[FLD_LEN]="";
    char replyto[FLD_LEN]="", inreplyto[FLD_LEN]="", ref[FLD_LEN]="";
    char rec[FLD_LEN]="", comments[FLD_LEN]="", keywords[FLD_LEN]="", return_path[FLD_LEN]="";
    char xapp[FLD_LEN]="";
    char resent_date[FLD_LEN]="", resent_from[FLD_LEN]="", resent_sender[FLD_LEN]="", resent_to[FLD_LEN]="", resent_cc[FLD_LEN]="", resent_bcc[FLD_LEN]="", resent_mid[FLD_LEN]="";
    char boundary[FLD_LEN]="--";
    char *str, *pstr;

    if(argc!=2)
      {printf("You forgot to enter a filename\n");
       exit(0);
      }

    if((fp=fopen(argv[1],"r"))==NULL)
      {printf("cannot open the file\n");
       exit(0);
      }

/*  read the email from a file  */


    lines=0;
    while(!feof(fp))
      {ch[i]=fgetc(fp);
       if(ch[i]=='\n') lines++;
       i++;
      }
    ch[i-1]='\0';
    fclose(fp);
    len=strlen(ch);

//815    printf("--------------------- Content of the Raw email---------------\n");
//815    printf("%s\n",ch);

 

//815    printf("--------------------- the end of the content ----------------\n");

//EXEC SQL SELECT MAX(case_no) INTO :caseno FROM raw_email;

EXEC SQL INSERT INTO raw_email (id,raw_email) VALUES (1,:ch);
EXEC SQL COMMIT;
printf("sql code is %d \n",SQLCODE);


//    printf("-----There are %d lines in the email.-----\n", lines);
//    printf("-----The character length is  %d -----\n", len);

/*  seperate the header and the message body  */

    split_head_from_body(ch,headers,body);

//    printf("-----------------------------------------\n");
//    printf("------The header of the email:--------\n");
//    printf("%s\n",headers);
//    printf("-----------------------------------------\n");

//    printf("-----------------------------------------\n");
//    printf("------The body of the email:--------\n");
//    printf("%s\n",body);
//    printf("-----------------------------------------\n");

/*  all the fields in an email header                */
/*  Bcc, Cc, Comments, Content-Type,                 */
/*  Content-Transfer-Encoding, Content-Disposition,  */
/*  Date, From, Keywords, Message-ID, MIME-Version,  */
/*  Organizaion, Received, Reference, Reply-To,      */
/*  Resent-From, Resent-To, Return-Path, Sender,     */
/*  Subject, To, X-***                               */

/*  Now, get the fields in the headers               */
/*  for limited fields                               */
/*       from, sender, reply-to, to, cc, bcc,        */
/*       message-id, in-reply-to, reference,         */
/*       subject                                     */

 

 limit_fields(headers,from,"From: ");
    limit_fields(headers,to,"To: ");
    limit_fields(headers,subject,"Subject: ");
    limit_fields(headers,date,"Date: ");
    limit_fields(headers,mesid,"Message-ID: ");
    limit_fields(headers,sender,"Sender: ");
    limit_fields(headers,cc,"Cc: ");
    limit_fields(headers,bcc,"Bcc: ");
    limit_fields(headers,replyto,"Reply-To: ");
    limit_fields(headers,inreplyto,"In-Reply-To: ");
    limit_fields(headers,ref,"Reference: ");

/*  new for MIME                                     */
/*       Mime-Version, Content-Type,                 */
/*       Content-ID, Content-Description,            */
/*       Content-Transfer-Encoding, Content-Length,  */
/*       Content-Disposition                         */

    limit_fields(headers,mime_version,"MIME-Version: ");
    limit_fields(headers,content_type,"Content-Type: ");
    limit_fields(headers,content_transfer_encoding,"Content-Transfer-Encoding: ");
    limit_fields(headers,content_id,"Content-ID: ");
    limit_fields(headers,content_description,"Content-Description: ");
    limit_fields(headers,content_length,"Content-Length: ");
    limit_fields(headers,content_disposition,"Content-Disposition: ");

/*  for unlimited fields    */
/*    (unlimited)                                    */
/*       comments, keywords,                         */
/*       Return-Path, Received,                      */
/*       Resent-Date, Resent-From,                   */
/*       Resent-Sender, Resent-To,                   */
/*       Resent-Cc, Resent-Bcc,                      */
/*       Resent_Message-ID, X-***                    */

     unlimit_fields(headers,rec,"Received: ");
     unlimit_fields(headers,comments,"Comments: ");
     unlimit_fields(headers,keywords,"Keywords: ");

 

unlimit_fields(headers,return_path,"Return-Path: ");

     unlimit_fields(headers,resent_date,"Resent-Date: ");
     unlimit_fields(headers,resent_from,"Resent-From: ");
     unlimit_fields(headers,resent_to,"Resent-To: ");
     unlimit_fields(headers,resent_sender,"Resent-Sender: ");
     unlimit_fields(headers,resent_cc,"Resent-Cc: ");
     unlimit_fields(headers,resent_bcc,"Resent-Bcc: ");
     unlimit_fields(headers,resent_mid,"Resent-Msg-Id: ");
     unlimit_fields(headers,xapp,"X-");

/*   find out the boundary */
     parts(content_type, boundary, body,  part_num);

     return 0;

  }---------------------------------------------------------------END--------------------------------------------------------------------------------

On 8/16/06, Michael Fuhr <mike@fuhr.org> wrote:
On Wed, Aug 16, 2006 at 02:42:46PM -0400, Jasbinder Bali wrote:
> Tried everthing but nothing seems to work.
> :(

Could you provide a simplified but complete example that shows what
you're doing?  That is, all SQL statements and C code necessary to
create a table and whatever functions you're using.  I've done a
little testing and haven't been able to reproduce your results, so
apparently my tests don't match what you're doing.

--
Michael Fuhr

pgsql-general by date:

Previous
From: Roman Neuhauser
Date:
Subject: Re: Triggers invoking a stored procedure or a C function
Next
From: "Jasbinder Bali"
Date:
Subject: Re: [NOVICE] DB insert Error