MySQL Forums
Forum List  »  Connector/C++

Prepared Statements - Incorrect behaviour
Posted by: Alex Freeman
Date: May 15, 2010 12:28PM

OS: Windows Vista, 32-bit
Compiler: Visual Studio 9 2008
Connecter: 1.0.5 binary and a local compiled from source.

// Statements
// **********

static void test_statements(Connection *con)
{
Statement *stmt;
stmt = con -> createStatement();

for (int index = 1; index <= 10; index++)
{
stringstream out;
out << index;
string query = "UPDATE test_2_events SET Name=";
query += "'T";
query += out.str();
query += "' WHERE ID=";
query += out.str();
stmt -> executeUpdate(query);
}

delete stmt;
}

// Prepared Statements
// **********

static void test_statements_prepared(Connection *con)
{
PreparedStatement *prep_stmt;
prep_stmt = con -> prepareStatement("UPDATE test_2_events SET Name=? WHERE ID=?");

for (int index = 5; index <= 10; index++)
{
stringstream out;
out << index;
string name = "T";
name += out.str();

// Nothing happens!
// Changing ID=? to ID=1 results in the name of ID=1 becomes 0 and not T(index).
prep_stmt -> setString(1, name);
prep_stmt -> setInt(2, index);
prep_stmt -> executeUpdate();
}

delete prep_stmt;
}

// End of code
// **********

Statements:
- This works correctly. It sets the name to T(index) for all IDs in the range 1-10.

Prepared Statements:
- Nothing happens unless ID=? gets changed to ID=1 etc. where the name will be set to 0 instead of T1.

I have used both the precompiled and compiled the connector from the source, but the result is the same.

Options: ReplyQuote


Subject
Views
Written By
Posted
Prepared Statements - Incorrect behaviour
2542
May 15, 2010 12:28PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.