I have the below sample program...
int main(void)
{
char insertQuery[] = "INSERT INTO ABCD_TABLE VALUES('987','31-AUG-16','19-JAN-17','901',
'31-DEC-12','1',\'\',\'\',\'\',\'\',\'\',\'\',\'ÜÜcreate02_de,ää\')";
connectToSQLServer();
executeINSERTQuery(insertQuery);
return 0;
}
When I run the program, the query is inserted successfully into the DB but the ÜÜ is shown as garbage.
When I run the same query manually in Toad, it is inserted proprly and the ÜÜ is shown properly in Toda.
"INSERT INTO ABCD_TABLE VALUES('987','31-AUG-16','19-JAN-17','901','31-DEC-12','1','','','','','','','ÜÜcreate02_de,ää')";
What might be the issue?
Please do let me know if you guys need the code sample of connectToSQLServer() and executeINSERTQuery(insertQuery). I will provide.
You have set NLS_LANG variable to ALL32UTF8. Also there is a way how to do it on OCI level, see: OCIEnvNlsCreate and Database Globalization Support Guide.
By doing this you till tell the OCI driver that everything you store in buffers is in UTF8 charset, and everything withdrawn from from database also must be in UTF8.
PS: note that some OCI api functions do distinguish number of bytes and number of characters. So for example you must not use OCILobRead/OCILobWrite to manipulate CLOBS. You must use extended versions OCILobRead2/OCILobWrite2.
Related
Am trying to determine how to compact an Access database using the .accdb ODBC driver. Note that I'm aware of how to accomplish this using the old .mdb driver, essentially something like this:
const TCHAR *Driver = TEXT("Microsoft Access Driver (*.mdb)");
TCHAR *DatabasePath = GetRegDBPath() ;
_stprintf_s(Attr, sizeof(Attr)/sizeof(TCHAR), TEXT("COMPACT_DB=%s%s %s%s General"), DatabasePath,
DBName,
DatabasePath,
DBName ) ;
Ret = SQLConfigDataSource(hPar,
ODBC_ADD_DSN,
Driver,
Attr);
However substituting the Driver string with Microsoft Access Driver (.mdb, .accdb), the call fails and calling *SQLInstallerError *to obtain error information comes back with (the rather unhelpful) message: Driver's ConfigDSN, ConfigDriver, or ConfigTranslator failed.
I've tried varations on the above syntax, using a different output database path, omitting the General parameter, all yield the same result.
This link suggests it can't be done but I'm sceptical because it's possible to do it from the ODBC Administrator Panel. Additionally looking through the ACEODBC.DLL for string content shows the presence of the COMPACT_DB strings:
jon#monolith:~/temp$ strings -t x -e l ACEODBC.DLL | grep -i compact
395f0 COMPACT_DB
39978 COMPACT_DB=%s
All suggests it should be possibe if I knew what the correct syntax is.
As far as I know, no, ODBC was never able to compact a access database.
your posted code does a printf (simple outputs some text), and that certainly would not and does not do a compact database. the next line of code "might" C + R the datbase, but that code is not posted.
eg:
SQLConfigDataSource
And I suppose it also possible that the TEXT() method used in above might have some code, but then again, you have to provide what that TEXT() method does then.
From what I can find?
You have to create a "com" object instance of the Access database engine (JET for mdb files, and ACE for accDB files).
I'm creating a program to communicate with the EPP like if I press any key the application should recognise it and print it back for now for illustration on how to create an application to communicate with the EPP.
Thank you.
I've found what I will call a function on "cwa 14050-6:2005" on page 42 "WFS_CMD_PIN_GET_DATA" and the description states that "This function is used to return keystrokes entered by user." My problem is writing or calling this function and when you go to page 43 on the output param "LPWFSPINDATA lpPinData;" which the "typedef" of it contains I will say a variable "lpPinKeys" which points to an array of pointers to WFSPINKEY structures that contains the keys entered by the user. So after going through this document I saw that in my case I need this, this is because when let's say I key in 1234 enter the application can be able to assign 1234 to a variable so that it can be verified and enter will cause the app to begin the keys verification to see if they match that's from database/server database and if they do then the app will call the relevant service else error will be displayed.
My main problem is calling this within my app. Even if the app can for now display back or assign the keys to a variable from a PIN pad (EPP). For now I don't use any encrypt just want to get and verify the plain keys.
If you require EPP development for NCR machines, you have to use Key Library API. This is not a part of CEN XFS standard, but is explained in the NCR XFS documentation.
I am developing a game using cocos2d-x and C++, and I need to load a bunch of YAML files for this application. I tried using the yaml-cpp library with quite good results.
The problem is that this library seems to be very unstable (at least under cocos2d-x on iOS), since almost 20% of the time it fails loading the same YAML file throwing "end of map not found", "invalid map element", or errors like these ones.
I followed the HowToParseADocument guide, so I think I got it correct. But, since it's not 100% reliable, I am looking for something more stable. Eg:
long size = 0;
unsigned char *yaml = FileUtils::getInstance()->getFileData("file.yml", "r", &size);
std::stringstream is;
is << yaml;
YAML::Parser parser(is);
YAML::Node doc;
while(parser.GetNextDocument(doc)) {
instance->settings = doc.Clone();
}
The parser usally breaks at the parser.GetNextDocument(doc) call. The document I am trying to read is plain YAML with key: value lists in this simple form:
# Comment
section1:
param1: value1
param2: value2
# Comment
section2:
param1: value1
param2: value2
Edit
I am not allowed to disclose the content of the original YAML file, but I can give you some information:
It only contains maps, and not arrays, aliases or other particular constructs
Those values are integers, float or strings
It has been linted with this free tool, with success.
The code I used to read it, posted up there, it's always in that form, and I do not modify it to make the app run correctly. It's just that the app starts and works or starts and does not work. Since I am changing nothing in the middle, I really do not understand what's happening.
It's a bit hard to guess at the solution because you won't provide an actual example, but:
Who owns the data at the unsigned char* returned by getFileData? If that function itself owns the data, then it is no longer valid after the function returns, and so all sorts of crazy stuff might happen.
To validate what's happening here (beyond looking at the implementation of getFileData), you could print out is.string() before calling YAML::Parser parser(is); and see if that prints the expected YAML.
I'm using the MySQL Connector/C++ to communicate with a MySQL server from a C++ program. For some reason (see below for the background), I need at some point the native C API connection structure. How do I get it from the Connector/C++ classes?
Background:
I want to load a huge amount of data (up to 2-3 billion tuples) from the client's main memory into the server. Therefore, I want to try the LOAD DATA INFILE statement. To avoid to write the whole data to a text file first, I want to define my own local infile handler, which reads the data directly from the main memory.
However, the Connector/C++ comes with no method to set user-defined local infile handlers, but the native C API does. The corresponding C function mysql_set_local_infile_handler() needs a native connection handler (the structure MYSQL) as input parameter. So how do I get this handler from the Connector/C++? Or is there any better way to set the local infile handler in a Connector/C++ environment?
You want sql::mysql::NativeAPI::MySQL_NativeConnectionWrapper::mysql, but it is a private member that is not returned by any method. Therefore, to access the structure, you will have to fork the Connector/C++ source and compile your own connector.
If that's the path you take, you might prefer to provide access to mysql_set_local_infile_handler() from within Connector/C++.
There is another way to work it around via the help of c++ command "system".
1) set the mysql environment in my.cnf: local-infile=1. You can find this file here: how to know mysql my.cnf location. Or just add option mysql --local-infile [other options] in the shell command line mentioned below.
2) In your c++ code, instead of using stmt->execute(...) from c++ connector, using
system("mysql -u username --database=dbname --password=pw -e \"LOAD DATA LOCAL INFILE filename INTO TABLE tablename FIELD TERMINATED BY ',' LINES TERMINATED BY '\n' (column1, column2, column3);\"");
The char array could also be manipulated in the program. Though it seems "low-tech", it does get work done in my project.
I am helping a friend with his bachelor thesis project. It is a program that calculates bending moments for various materials. One of the extra requirements that the client desires is database functionality to store and retrieve various pieces of data being used in the program.
The program is a forms application written in managed C++. I jumped on board to help with writing the database functionality. I am using MySQL Server 5.5 and the MySQL Connector/C++ to bridge the program and the database. Everything has been going pretty well and all the functionality we need works just fine, but only in debug. As soon as we put the program into release mode there is undefined behavior occurring at runtime. Below is the function that is used to open a connection to the database:
try
{
m_driver = get_driver_instance();
m_conn = m_driver->connect(m_dbHost, m_dbUser, m_dbPwd);
m_conn->setSchema(m_dbSchema);
}
catch(sql::SQLException &e)
{
int a = e.getErrorCode();
MessageBoxA(NULL, e.what(), "DB Error", MB_OK);
}
The values passed into the connect function are all std::string. In debug mode the connection is made with no issues. In release mode an exception is caught after the connect function is called, and displays the message "Unknown MySQL Server Host '####' (0)" where the #### is always some garbage text. I also notice that in the output window another exception is being thrown, this one is the type System.Runtime.InteropServices.SEHException.
I have been doing some research and have seen numerous cases of this exception on many forums (and here on stack exchange) but no one seems to be having this issue with the MySQL connector. My assumption is that the memory is being corrupted because the program is mixed mode, with the main program code being written in Managed C++ and my database helper code being in native C++ (as required by the connector).
Is there something I can change in my code to try and fix this issue to that the strings aren't being corrupted at run time. I have tried many different hacks to try and solve the problem but nothing has worked.
Thanks,
Tom
Update: I am now seeing this error in debug mode. I added code to retrieve values from the database and populate some text boxes on the form. The code is as follows:
// Populate the form with material details
String^ selectedMaterial = (String^)(comboBox1->SelectedItem);
string selectedMaterial_ = "";
MarshalString(selectedMaterial, selectedMaterial_);
sql::ResultSet* results = dbHelper.GetData("matname", selectedMaterial_);
if (results->rowsCount() == 1)
{
// Outdim
string outdim_ = "";
outdim_ = results->getString("outdim");
String^ outdim = gcnew String(outdim_.c_str());
textBox1->Text = outdim;
}
else
{
// !!!! Duplicate materials in list
}
When it tries to read outdim from the result set the SEHException is thrown, and the only other piece of information given is that it was thrown in an external component.
Update 2: I ran Application Verifier against the debug executable and then launched the program from VS2010. However the form window never loads so somewhere along the line the program must be getting halted. Strangely there is absolutely no information in the log files in Application Verifier. I also tried with the release version and I didnt get any useful information from that either.