[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
EmbeddedSqlC

Embedded SQl in C

/* 
    • QUERY001.C
    • Programmed by Richel Bilderbeek at 27-11-2006
    • Problem:
    • Every case_id needs to have unique interr_id's.
    • For case_id = '00066967' there are two interr_id = '8@@@@@@'.
    • Solution:
    • This program updates a single interr_id to '9@@@@@@'
    • /
  1. include <stdio.h>
exec sql include SQLCA;
  1. pragma mapinc("INTERR","*LIBL/INTERR(*ALL)","both","D Z",,"INTERR")
int main() { long count = -1; //'int' is not supported by SQL printf("Start of Query001.c\n"); /* Count cases to be modified */ exec sql select count(*) into :count from INTERR where case_id = '00066967' and interr_id = '8@@@@@@' and verwijderd <> 'J'; if (count==0) { printf("Error: Case not found!\n"); return 1; } else if (count>2) { printf("Error: More cases found!\n"); return 2; } /* Perform the update */ exec sql update INTERR set interr_id = '9@@@@@@' where case_id = '00066967' and interr_id = '8@@@@@@' and verwijderd <> 'J'; /* Again, count cases to be modified */ exec sql select count(*) into :count from INTERR where case_id = '00066967' and interr_id = '8@@@@@@' and verwijderd <> 'J'; if (count==0) { printf("Succesful update"); return 0; } else { printf("Error: Unsuccesful update: count equals %i",count); return 3; } }


Note:
  • You cannot put a macro in an Embedded SQL statement
  • You cannot store values from COUNT in an integer, but in a long.

External links



last edited (December 6, 2006) by bilderbikkel, Number of views: 1591, Current Rev: 7 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.