/************************************************ Function:* * * * * Extract database records ****************************************** *******/intExtract_data (Char*efilename,Const Char*sqlname) {FILE*Fpwrite; EXEC SQL BEGIN DECLARE section; varchar v_str_sql[ the+1];/*SQL statements*/varchar Vc_expcol[maxlen]; EXEC SQL END DECLARE section; /**/strcpy ((Char*) v_str_sql.arr,sqlname); V_str_sql.len=strlen ((Char*), #ifdef DEBUG printf (v_str_sql.arr)"SQL statement%s.\n", V_str_sql.arr);#endifEXEC SQL whenever SQLERROR GOTO prepare_exp_error; if(Fpwrite = fopen (Efilename,"w+")) ==NULL) {fprintf (stderr,"cannot open data file%s\n", Efilename); Exit (1); } /*declaring how cursors are handled*/EXEC SQL PREPARE sqlstmt from:v_str_sql; EXEC SQL DECLARE extract_cur CURSOR for sqlstmt; EXEC SQL OPEN extract_cur; for(;;) { /*Extracting Data*/EXEC SQL FETCH extract_cur into:vc_expcol; if(Sqlca.sqlcode = =1403) {fprintf (stderr,"data has been extracted or there are no qualifying data!\n"); Break; } Vc_expcol.arr[vc_expcol.len]=' /'; /*log output data to a file*/fprintf (Fpwrite,"%s\n", Vc_expcol.arr); } /*Close File*/fclose (Fpwrite); /*Close Cursors*/EXEC SQL CLOSE extract_cur; returnSuccess;prepare_exp_error:/*Log error Messages*/fprintf (stderr,"\n%70s\n", SQLCA.SQLERRM.SQLERRMC); fprintf (stderr,"Database operation Error! Exit! "); returnFailuer;}
ETL application: How to implement file extraction using Pro*c