ORA-00904: "E_MAIL": invalid identifier - c++

I am using MVC architecture.I am trying to update a record in a table taking customer id as input.
all the data is taken as input in my viewcustomer.cpp class whose method is returning an object of type customer which is passed to a function in modelcustomer.pc via controlcustomer.cpp(controller)
Following is a function of my modelcustomer.pc
void modelcustomer::dbUpdateCustomerDetail(customer &c)
{
id=c.getId();
ph=c.getId();
string memberFName=c.getFname();
string memberLName=c.getLname();
string memberStreet=c.getStreet();
string memberCity=c.getCity();
string memberState=c.getState();
string memberEmail=c.getEmail();
fn=new char[memberFName.length()+1];
ln=new char[memberLName.length()+1];
street=new char[memberStreet.length()+1];
city=new char[memberCity.length()+1];
state=new char[memberState.length()+1];
e_mail=new char[memberEmail.length()+1];
strcpy(fn,memberFName.c_str());
strcpy(ln,memberLName.c_str());
strcpy(street,memberStreet.c_str());
strcpy(city,memberCity.c_str());
strcpy(state,memberState.c_str());
strcpy(e_mail,memberEmail.c_str());
if(dbConnect())
{
EXEC SQL UPDATE CUSTOMER_1030082 SET CID=:id,FNAME=:fn,LNAME=:ln,PHONE=:ph,STREET=:street,STATE=:state,CITY=:city,EMAIL=e_mail;
if(sqlca.sqlcode<0)
{
cout<<"error in execution"<<sqlca.sqlcode<<sqlca.sqlerrm.sqlerrmc;
}
EXEC SQL COMMIT WORK RELEASE;
}
}
when i'm running it a menu is displayed with some options ,i select the update option then it asks me for new details and after that i'm getting following output:
connected to Oracle!
error in execution-904ORA-00904: "E_MAIL": invalid identifier

e_mail is not a parameter, you forgot ::
EXEC SQL … EMAIL=:e_mail;
↑

Related

How to set a NULL column value through an ADO query connected to a MySQL ODBC source in C++?

Given a given MySQL table
DESC tabl_foo;
--------------------------------
Field Type Null Key Default Extra
-----------------------------------------------------------------
fooId varchar(15) NO PRI NULL
FooDate date YES MUL NULL
I need to update FooDate for a given row. So I tried this code :
query->SQL->Add("UPDATE tbl_foo SET FooDate = :FooDate WHERE fooId = :id"):
// both arguments are AnsiString
query->Parameters->FindParam("id")->Value = FoodId;
query->Parameters->FindParam("FooDate")->Value = FooDate;
query->ExecSQL();
However, this fails
Incorrect date value: "" for folumn FooDate at row 1
It turns out that FooDate may be an empty string (or { data:NULL }), and MySQL does not like that. So, I tried setting Null() :
if (FooDate.IsEmpty())
query->Parameters->FindParam("FooDate")->Value = Null();
else
query->Parameters->FindParam("FooDate")->Value = FooDate;
But then I get this error :
Parameter object is improperly defined. Inconsistent or incomplete information was provided.
What should be the value to set for MySQL NULL?
To make the update the system needs to know the types of the parameters. It can deduce the type from the variant you apply, and MySQL can do certain conversions for you, but it's always best to specify the data type.
So what you would need is something like:
if((pParam=query->Parameters->FindParam("FooDate"))!=NULL)
{
pParam->DataType=ftDate;
if(FooDate.IsEmpty())
{
pParam->Value=Null();
}
else
{
pParam->Value=FooDate;
}
}
You may want to look at keeping FooDate as a TDateTime, but you will need to detect NULL dates properly.

ORA-00947: not enough values when creating object in Oracle

I created a new TYPE in Oracle in order to have parity between my table and a local c++ object (I am using OCCI interface for C++).
In the code I use
void insertRowInTable ()
{
string sqlStmt = "INSERT INTO MY_TABLE_T VALUES (:x)";
try{
stmt = con->createStatement (sqlStmt);
ObjectDefinition *o = new ObjectDefinition ();
o->setA(0);
o->setB(1);
o->setC(2);
stmt->setObject (1, o);
stmt->executeUpdate ();
cout << "Insert - Success" << endl;
delete (o);
}catch(SQLException ex)
{
//exception code
}
The code compiles, connects to db but throws the following exception
Exception thrown for insertRow Error number: 947 ORA-00947: not enough
values
Do I have a problematic "sqlStmt"? Is something wrong with the syntax or the binding?
Of course I have already setup an environment and connection
env = Environment::createEnvironment (Environment::OBJECT);
occiobjm (env);
con = env->createConnection (user, passwd, db);
How many columns are in the table? The error message indicates that you didn't provide enough values in the insert statement. If you only provide a VALUES clause, all columns in the table must be provided. Otherwise you need to list each of the columns you're providing values for:
string sqlStmt = "INSERT INTO MY_TABLE_T (x_col) VALUES (:x)";
Edit:
The VALUES clause is listing placeholder arguments. I think you need to list one for each value passed, e.g.:
string sqlStmt = "INSERT INTO MY_TABLE_T (GAME_ID, VERSION) VALUES (:x1,:x2)"
Have a look at occidml.cpp in the Oracle OCCI docs for an example.

Doctrine error "Invalid parameter number: number of bound variables does not match number of tokens"

I'm building a Symfony 1.4.20 application and I wrote this code:
public function getListForAdmin() {
$user = sfContext::getInstance()->getUser();
$q = $this->createQuery('g');
if ($user->hasCredential('can_admin_full')) {
$q->addWhere('g.name IN (?)', array('Administradores Monitor', 'Monitor'));
} else if ($user->hasCredential('can_admin')) {
$q->addWhere('g.name IN (?)', array('Monitor'));
}
return $q;
}
Seeing in Symfony logs the result query is as follow:
SELECT s.id AS s__id, s.name AS s__name, s.description AS s__description, s.created_at AS s__created_at, s.updated_at AS s__updated_at
FROM sf_guard_group s
WHERE (s.name IN ('Administradores Monitor'))
I run the query in phpMyAdmin and all is fine meaning query doesn't have any problem but in Symfony with Doctrine I get this error:
SQLSTATE[HY093]: Invalid parameter number: number of bound variables
does not match number of tokens
Why? What's wrong?
I think that problem in this rows:
$q->addWhere('g.name IN (?)', array('Administradores Monitor', 'Monitor'));
and
$q->addWhere('g.name IN (?)', array('Monitor'));
It should be:
$q->whereIn('g.name', array('Administradores Monitor', 'Monitor'));
and
$q->whereIn('g.name', array('Monitor'));
UPDATE: edit answer

Error in Update query [Using String.Format]

I am trying to write an update statement for inserting data from asp.net gridview to sql server 2005 database.but it is showing me an error, Please tell me how to solve.
cmdUpdate.CommandText = String.Format("Update Products SET ProductName=
{0},UnitsInStock={1},UnitsOnOrder={2},ReorderLevel={3} WHERE ProductID={4} AND
SupplierID={5}", "productname.Text, unitsinstock.Text, unitsonorder.Text,
recorderlevel.Text, employeeid.Text, supplierid.Text");
Error is-
Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
Your syntax for string.Format is incorrect - each parameter after the string template should be on their own, without the double quotes surrounding them all...
This will work (notice I've removed the double quotes from just before 'productname.Text' and after 'supplierid.Text'):
String.Format("Update Products SET ProductName={0}, UnitsInStock={1}, UnitsOnOrder={2}, ReorderLevel={3} WHERE ProductID={4} AND SupplierID={5}",
productname.Text, unitsinstock.Text, unitsonorder.Text,
recorderlevel.Text, employeeid.Text, supplierid.Text);
You missed the arguments,
For instance,
str=String.Format("{0} {1}",arg1,arg2);
Do not use hard-coded sql strings. Try to learn/use parameterized queries.
EDIT:
string ConnectionString = "put_connection_string";
using (SqlConnection con = new SqlConnection(ConnectionString))
{
using (SqlCommand cmd = new SqlCommand())
{
string sql = "Update Products SET
ProductName=#ProductName,
UnitsInStock=#UnitsInStock,
UnitsOnOrder=#UnitsOnOrder,
ReorderLevel=ReorderLevel
WHERE ProductID=ProductID AND SupplierID=#SupplierID";
cmd.CommandText = sql;
cmd.Connection = con;
cmd.Parameters.Add("#ProductName", System.Data.SqlDbType.VarChar, 50).Value =productname.Text;
cmd.Parameters.Add("#UnitsInStock", System.Data.SqlDbType.Int).Value =unitsinstock.Text;
cmd.Parameters.Add("#UnitsOnOrder", System.Data.SqlDbType.Int).Value =unitsonorder.Text;
cmd.Parameters.Add("#ReorderLevel ", System.Data.SqlDbType.Int).Value =recorderlevel.Text;
cmd.Parameters.Add("#ProductID", System.Data.SqlDbType.Int).Value =producteid.Text;
cmd.Parameters.Add("#SupplierID", System.Data.SqlDbType.Int).Value =supplierid.Text;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
EDIT: What is C# using block?
If the type implements IDisposable, it automatically disposes it
Provides a convenient syntax that ensures the correct use of IDisposable objects.
Avoiding Problems with the Using Statement

Testing NHibernate with SQLite "No Such Table" - schema is generated

I'm trying to use an in-memory SQLite database to test my data layer which is provided by NHibernate.
I've read a load of blogs and articles about getting this setup but I'm now very confused as to why it isn't working.
The problem - when I run a unit test I get the error 'no such table: Student'. The articles I've read suggest this is because the schema isn't getting generated, or, the connection is being closed between my SchemaExport and query. I've checked everywhere I can think of and can't see how either of these scenarios are occuring.
My test output log looks like this:
OPEN CONNECTION
drop table if exists "Student"
drop table if exists "Tutor"
create table "Student" (
ID integer,
Name TEXT,
DoB DATETIME,
TutorId INTEGER,
primary key (ID)
)
create table "Tutor" (
ID integer,
Name TEXT,
primary key (ID)
)
NHibernate: INSERT INTO "Student" (Name, DoB, TutorId) VALUES (#p0, #p1, #p2); select last_insert_rowid();#p0 = 'Text1', #p1 = 01/12/2010 14:55:05, #p2 = NULL
14:55:05,750 ERROR [TestRunnerThread] AbstractBatcher [(null)]- Could not execute query: INSERT INTO "Student" (Name, DoB, TutorId) VALUES (#p0, #p1, #p2); select last_insert_rowid()
System.Data.SQLite.SQLiteException (0x80004005): SQLite error
no such table: Student
at System.Data.SQLite.SQLite3.Prepare(String strSql, SQLiteStatement previous, String& strRemain)
at System.Data.SQLite.SQLiteCommand.BuildNextCommand()
at System.Data.SQLite.SQLiteCommand.GetStatement(Int32 index)
at System.Data.SQLite.SQLiteDataReader.NextResult()
at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.SQLite.SQLiteCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd)
14:55:05,781 ERROR [TestRunnerThread] ADOExceptionReporter [(null)]- SQLite error
no such table: Student
DISPOSE
CLOSING CONNECTION
Originally I was using my own code for the connection/session management but have moved to the code in this blog post translated to C# and with a couple changes to the DBConfig method and some debug statements to show the state of the connection.
private FluentNHibernate.Cfg.Db.IPersistenceConfigurer GetDBConfig()
{
return SQLiteConfiguration.Standard
.ConnectionString((ConnectionStringBuilder cs) => cs.Is(CONNECTION_STRING))
.ProxyFactoryFactory("NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu")
.Raw("connection.release_mode", "on_close");
}
I added the on_close after reading this
My test code looks like this:
[Test]
public void CanGetStudentById()
{
using (var scope = new SQLiteDatabaseScope<StudentMapping>())
{
using (ISession sess = scope.OpenSession())
{
// Arrange
var repo = new StudentRepository();
repo.Save(new Student() { Name = "Text1", DoB = DateTime.Now });
// Act
var student = repo.GetById(1);
// Assert
Assert.IsNotNull(student);
Assert.AreEqual("Text1", student.Name);
}
}
}
What have I overlooked here?
Update: I created a copy of the class that connects to an SQLite file DB and it worked fine. So it has to be something to do with the connection being closed.
If you change your test method to the following, does it work?
[Test]
public void CanGetStudentById()
{
using (var scope = new SQLiteDatabaseScope<StudentMapping>())
{
using (ISession sess = scope.OpenSession())
{
// Arrange
sess.Save(new Student() { Name = "Text1", DoB = DateTime.Now });
// Act
var student = sess.Get<Student>(1);
// Assert
Assert.IsNotNull(student);
Assert.AreEqual("Text1", student.Name);
}
}
}
I would hazard to guess that your StudentRepository is opening its own session and hence doesn't see the table.