Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C with embedded oracle sql example

Posted on 1999-07-07
6
Medium Priority
?
179 Views
Last Modified: 2010-04-15
can anyone provide me with a sample program which reads a text file, then inserts parts of the line into an oracle database?
0
Comment
Question by:wchiang
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1263373
do you want to use the oracle API, or compute a sqlplus statement to be called by system() ?
For the API there should be enough examples coming with oracle.
0
 

Author Comment

by:wchiang
ID: 1263374
I guess the oracle api. This is what I have so far. Does it look like something workable? I got it parts of it from an oracle book.

int main(int argc, char **argv)
{
      FILE      *fp;
      char      buffer[MAX_NISDATALEN];

//check local error log
      if (  ( fp = fopen( LOC_ERR_LOG, "r") ) == (FILE *) NULL )
            return( 0 );
      else
      {
            //handle errors
            EXEC SQL WHENEVER SQLERROR do sql_error();

            //connect to Oracle
            EXEC SQL CONNECT :userid;

            while ( fgets( buffer, MAX_NISDATALEN, fp ) != NULL )
            {
                  //insert data
                  EXEC SQL
                  INSERT INTO err_log (INSERT_DATETIME, INSERT_USER_ID, ERR_CODE,
                                          ERR_REASON_CODE, MSG_ID, ERR_CAT, ERR_FUNC_AREA,
                                          ERR_TRAN_TYPE, MOD_RPT, PREV_MOD, ERR_TEXT,
                                          ERR_TEXT_LGTH, TRAN_DATA, TRAN_LGTH)
                  VALUES (:errDate, :eaUserId, :eaErrCode, :eaRelMsgID, :eaErrCategory,
                              :eaErrFuncArea, :eaErrTransType, :eaModule, :eaPrevModule,
                              :eaErrText, :eaErrTextLength, :eaTranData, :eaTranDataLength);
            }

            EXEC SQL COMMIT WORK RELEASE;
            fclose( fp );
            remove( LOC_ERR_LOG );

            void sql_error()
            {
                  EXEC SQL WHENEVER SQLERROR CONTINUE;
                  EXEC SQL ROLLBACK WORK RELEASE;
            }
      }

0
 
LVL 2

Expert Comment

by:hougaard
ID: 1263375
That looks like a mixture of SQL and C :-)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 51

Expert Comment

by:ahoffmann
ID: 1263376
should work (have not tested).
But I miss the oracle includes and the definition of the host variables.
0
 

Author Comment

by:wchiang
ID: 1263377
ahoffmann,
that's good for now. You want to post your answer so I can give you the points?
thanks
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 200 total points
ID: 1263378
should work (have not tested).
But I miss the oracle includes and the definition of the host variables.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question