Home » Developer & Programmer » Precompilers, OCI & OCCI » Insert problem
Insert problem [message #94091] Mon, 02 February 2004 02:55
antreas
Messages: 5
Registered: January 2004
Junior Member
Hi all.I have the following program and though it works fine when i give it the right elements,it doesn't print me the error when one happens.

----------------------------------------------------------------------

<html>

[i]

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

#define UNAME_LEN 20
#define PWD_LEN 11

typedef char asciiz[[PWD_LEN]];
EXEC SQL TYPE asciiz IS CHARZ(PWD_LEN) REFERENCE;
asciiz username;
asciiz password;

EXEC SQL include SQLCA;

void do_connect();
void sql_error(char* routine);

struct {
varchar licencenumber[[7]];
varchar company[[10]];
varchar model[[10]];
varchar color[[15]];
int madeyear;
}vehicle;

int main(void) {

 int i;
    /* Connect to ORACLE. */
 do_connect();
 
 printf("Give licencenumber:");
 scanf("%s",vehicle.licencenumber.arr);
 vehicle.licencenumber.len=strlen((char *)vehicle.licencenumber.arr);
 for(i=0;i<vehicle.licencenumber.len;i++)
  vehicle.licencenumber.arr[[i]]=toupper(vehicle.licencenumber.arr[[i]]);
 printf("Give company name(10 chars maximum):");
 scanf("%s",vehicle.company.arr);
 vehicle.company.len=strlen((char *)vehicle.company.arr);
 for(i=0;i<vehicle.company.len;i++)
  vehicle.company.arr[[i]]=toupper(vehicle.company.arr[[i]]);
 printf("Give vehicle's model(10 chars maximum):");
 scanf("%s",vehicle.model.arr);
 vehicle.model.len=strlen((char *)vehicle.model.arr);
 for(i=0;i<vehicle.model.len;i++)
  vehicle.model.arr[[i]]=toupper(vehicle.model.arr[]);
 printf("Give vehicle's color:");
 scanf("%s",vehicle.color.arr);
 vehicle.color.len=strlen((char *)vehicle.color.arr);
 printf("Give vehicle's made year:");
 scanf("%d",&vehicle.madeyear);
 
 EXEC SQL WHENEVER SQLERROR DO sql_error("Oracle error:");
 EXEC SQL INSERT INTO CAR
 VALUES(:vehicle);
 

 
    /* Disconnect from ORACLE. */
        EXEC SQL COMMIT WORK RELEASE;
        exit(EXIT_SUCCESS);
}

/* Connect to the database. */
void do_connect()
{
  strcpy(username,"??????????????");
  strcpy(password,"???????");

  EXEC SQL WHENEVER SQLERROR DO sql_error("do_connect():CONNECT");
  EXEC SQL CONNECT :username IDENTIFIED BY :password;

  printf("Connected to ORACLE as user %sn",username);
}

void sql_error(char* routine)
{
  char message_buffer[[512]];
  size_t buffer_size;
  size_t message_length;

  /* Turn off the call to sql_error() to avoid a possible infinite loop */
  EXEC SQL WHENEVER SQLERROR CONTINUE;

  printf("nOracle error while executing %s!n", routine);
  printf("nError while inserting:n");
  printf("%s  %s  %dn",vehicle.company.arr,vehicle.model.arr,vehicle.madeyear);
 
  /* Use sqlglm() to get the full text of the error message. */
  buffer_size = sizeof(message_buffer);
  sqlglm(message_buffer, &buffer_size, &message_length);
  printf("%.*sn", message_length, message_buffer);

  EXEC SQL ROLLBACK WORK RELEASE;
  exit(EXIT_FAILURE);
}

----------------------------------------------------------------------



</html>

For example it does not give me any referential constraints error that happen during the insertion of a new vehicle.

The table car is the following:

CREATE TABLE CAR

(LICENCENUMBER VARCHAR(7) NOT NULL,

FIRM VARCHAR(10) NOT NULL,

MODEL VARCHAR(10) NOT NULL,

COLOR VARCHAR(15),

YEAR INT NOT NULL,

PRIMARY KEY(LICENCENUMBER),

FOREIGN KEY(FIRM,MODEL) REFERENCES AUTO(FIRM,MODEL)

ON DELETE SET NULL);

 

I know that it can be a very stupid mistake that i have done,but i'm stuck now and i can't find it.If anyone has any suggestions i would be very glad to hear them.

Thanx.
Previous Topic: Pb when linking on hp10.20 with Oracle 8.0.6 : pthread
Next Topic: Pro *c pre compilation
Goto Forum:
  


Current Time: Sat Mar 02 17:08:52 CST 2024