Home » Developer & Programmer » Precompilers, OCI & OCCI » An error was occured for this query
An error was occured for this query [message #267709] Fri, 14 September 2007 06:07 Go to next message
abdelkaoui
Messages: 1
Registered: September 2007
Junior Member
I'm trying to execute this source code, but an error was occured. I can run this code by this query :

char *query = "select nom,prenom from client";


but when I add the condition like this:

char *query = "select nom,prenom from client where code =:c";


there are an error in result


char *query = "select nom,prenom from client where code =:c";

/* Allocate and prepare SQL statement */
   rc = OCIHandleAlloc( (dvoid *) p_env, (dvoid **) &p_sql,
           OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0);
   rc = OCIStmtPrepare(p_sql, p_err, (OraText *) query,
           (ub4) 37, (ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT);

   // Bind the values for the bind variables
   code = 1;
   rc = OCIBindByName(p_sql, &p_bnd, p_err, (text *) ":c",
           -1, (dvoid *) &code, sizeof(int), SQLT_INT, (dvoid *) 0,
           (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT);

   // Define the select list items
   rc = OCIDefineByPos(p_sql, &p_dfn, p_err, 1, (dvoid *) &nom,
           (sword) 20, SQLT_STR, (dvoid *) 0, (ub2 *)0,
           (ub2 *)0, OCI_DEFAULT);
   // Define the select list items
   rc = OCIDefineByPos(p_sql, &p_dfn, p_err, 2, (dvoid *) &prenom,
           (sword) 20, SQLT_STR, (dvoid *) 0, (ub2 *)0,
           (ub2 *)0, OCI_DEFAULT);

   // Execute the SQL statment
   rc = OCIStmtExecute(p_svc, p_sql, p_err, (ub4) 0, (ub4) 0,
           (CONST OCISnapshot *) 0, (OCISnapshot *) 0, OCI_DEFAULT);
	if(rc == OCI_SUCCESS)
	{
	   while (rc != OCI_NO_DATA) {/* Fetch the remaining data */
		  printf("%s %s \n",nom,prenom);
		  rc = OCIStmtFetch(p_sql, p_err, 1, 0, 0);
	   }
	}
	else
	{
		printf("Une erreur s'est produite dans l'execution de la requete SQL");
	}


Best regards

Abdelkaoui
Re: An error was occured for this query [message #267743 is a reply to message #267709] Fri, 14 September 2007 10:32 Go to previous messageGo to next message
Michel Cadot
Messages: 58861
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
I see neither any error nor Oracle version in what you posted .

Regards
Michel
Re: An error was occurred for this query [message #268099 is a reply to message #267743] Mon, 17 September 2007 09:10 Go to previous message
Frank Naude
Messages: 4419
Registered: April 1998
Senior Member
Is this still a problem? If so, please provide more info as suggested by Michel.
Previous Topic: Linking errors!!
Next Topic: Not connecting to Oracle in VC++2005
Goto Forum:
  


Current Time: Sat Aug 23 03:18:52 CDT 2014

Total time taken to generate the page: 0.09555 seconds