Contents:
Search: |
ExampleThe following are some snippets from the mql(1) program. They are placed under the MIT license as given at the beginning of the file src/mql.cpp in the Emdros sourcecode package. #include <emdfdb.h> #include <emdros_environment.h> #include <iostream> #include <sstream> #include <fstream> #include <string> // Not showing exec_file() function int exec_cin(EmdrosEnv *pEE) { bool bResult; std::string strError; int nResult; if (!pEE->executeStream(std::cin, bResult, true, true)) { std::cerr << "FAILURE: Database error executing stdin." << std::endl; nResult = 5; } else { if (!bResult) { // std::cerr << "FAILURE: Compiler error executing stdin." << std::endl; nResult = 6; } else { // std::cout << "SUCCESS executing stdin." << std::endl; nResult = 7; } } // Return result return nResult; } int main(int argc, char* argv[]) { // Set defaults eOutputKind output_kind = kOKConsole; std::string initial_db("emdf"); std::string filename; std::string hostname("localhost"); std::string user("emdf"); eBackendKind backend_kind = kSQLite2; // Could also be kPostgreSQL or kMySQL or kSQLite3 // Get default password std::string password; #if USE[PREUNDERSCORE}DEFAULT_PASSWORD getDefaultPassword(password); #else password = ""; #endif // Parse arguments if (!parse_arguments(argc, argv, output_kind, initial_db, filename, hostname, user, password)) { print_usage(std::cerr); return 1; } // Make connection EmdrosEnv *pEE = new EmdrosEnv(output_kind, kCSISO_8859_1, hostname, user, password, initial_db, backend_kind); // Zero-fill password zeroFillString(password); // Check that we connected if (!pEE->connectionOk()) { std::cerr << "Connection to backend server could not be established. Aborting." << std::endl; delete pEE; return 2; } int nResult = 3; try { if (filename == "") { nResult = exec_cin(pEE); } else { nResult = exec_file(pEE, filename); } } catch (EMdFDBException e) { std::cerr << "ERROR: EMdFDBException (Database error)..." << std::endl; std::cerr << pEE->getDBError() << std::endl; std::cerr << pEE->getCompilerError() << std::endl; } catch (BadMonadsException e) { std::cerr << "BadMonadsException caught. Program aborted." << std::endl; } catch (WrongCharacterSetException e) { std::cerr << "WrongCharacterSetException caught. Program aborted." << std::endl; } catch (EMdFOutputException e) { std::cerr << "EMdFOutputException caught. Program aborted." << std::endl; } catch (...) { std::cerr << "Unknown exception occurred. Program aborted." << std::endl; } // Clean up delete pEE; return nResult; } |