pro*c function Case 2--database operations

Source: Internet
Author: User
Tags sql error sql error code

Pro*c Oracle's embedded development, the Database Processing section is best able to extract a module, according to the operation of different database tables into different. pc files (such as dbsinststat.pc).
Compile this module into a library (the library is linked at compile time for C files), and the. c File processes the library table when you call the function in the corresponding database module (. pc).
function Case:

DbsDef.h

#defineDbs_init 0#defineDbs_select 1#defineDbs_lock 2#defineDbs_update 3#defineDbs_delete 4#defineDbs_insert 5#defineDbs_cursor 11#defineDbs_open 12#defineDbs_close 13#defineDbs_fetch 14#defineDbs_update2 15#defineSql_not_found_ret (Err_val)if(Sqlca.sqlcode = =1403) {Htlog (ERROR,"error code [%d], reason[%s] \ n", Sqlca.sqlcode, (Char*) SQLCA.SQLERRM.SQLERRMC);         strcpy (Gpubstru.sabankrespcode, err_val); return-1; }#defineSql_err_ret ()if(Sqlca.sqlcode! =0) {Htlog (ERROR,"SQL ERROR code [%d], reason[%s] \ n", Sqlca.sqlcode, (Char*) SQLCA.SQLERRM.SQLERRMC);         strcpy (Gpubstru.sabankrespcode, Sql_err); return-1 ; }#defineSql_err_ret2 ()if(Sqlca.sqlcode! =0&& Sqlca.sqlcode! =1403) {Htlog (ERROR,"SQL ERROR code [%d], reason[%s] \ n", Sqlca.sqlcode, (Char*) SQLCA.SQLERRM.SQLERRMC);         strcpy (Gpubstru.sabankrespcode, Sql_err); return-1 ; }

dbsinststat.pc

#include"public.h"#include"errlog.h"#include"DbsDef.h"#include"My_sys.h"EXEC SQL INCLUDE Sqlda; EXEC SQL INCLUDE Sqlca;    EXEC SQL BEGIN DECLARE section; Charsainstcode[ One+1]; CharSainsthsmindex [3+1]; CharSainstprimkey [ ++1]; CharSainstpinkey [ ++1]; CharSainstmackey [ ++1]; CharSainststat [1+1]; EXEC SQL END DECLARE section;intDbstblinststat (intNOPR) {    /*********** * Parameter Initialization ************/memset (Sainstcode,0x00,sizeof(Sainstcode)); memset (Sainsthsmindex,0x00,sizeof(Sainsthsmindex)); memset (Sainstprimkey,0x00,sizeof(Sainstprimkey)); memset (Sainstpinkey,0x00,sizeof(Sainstpinkey)); memset (Sainstmackey,0x00,sizeof(Sainstmackey)); memset (Sainststat,0x00,sizeof(Sainststat)); memcpy (Sainstcode, Gpubstru.safwdinstidcode,8);    Trimspace (Sainstcode); /*********** * Data processing ************/    Switch(NOPR) { Casedbs_select:exec SQL SELECT inst_hsm_index, Inst_prim_key, NVL (Inst_pin_key,' '), NVL (Inst_mac_key,' '), Inst_stat Into:sainsthsmindex,: Sainstprimkey,: Sainstpinkey,: Sainstmackey,: Sainststat FRO M tbl_inst_stat WHERE Inst_code=: Sainstcode;            Sql_not_found_ret2 ();        Sql_err_ret2 (); /****************** * Save data to internal IPC *******************/memcpy (Gpubstru.sainsthsmindex, Sainsthsmindex,4); memcpy (Gpubstru.sainstmainkey, Sainstprimkey, +); memcpy (Gpubstru.sapinkey, Sainstpinkey, +); memcpy (Gpubstru.samackey, Sainstmackey, +); memcpy (Gpubstru.sainststat, Sainststat,1);  Break;  Casedbs_update:exec SQL UPDATE tbl_inst_stat SET inst_stat='Y'WHERE Inst_code=: Sainstcode;            Sql_not_found_ret2 (); Sql_err_ret2 () Break;  Casedbs_update2:memcpy (Sainstmackey, Gpubstru.samackey1, -); EXEC SQL UPDATE tbl_inst_stat SET inst_mac_key=: Sainstmackey WHERE inst_code=: Sainstcode;            Sql_not_found_ret2 (); Sql_err_ret2 () Break; default:         Break; }    return 0;}

pro*c function Case 2--database operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.