00001 /*****************************************************************************\ 00002 * * 00003 * Name : test of handling special characters in database * 00004 * Author : Chris Koeritz * 00005 * * 00006 ******************************************************************************* 00007 * Copyright (c) 2008-$now By Author. This program is free software; you can * 00008 * redistribute it and/or modify it under the terms of the GNU General Public * 00009 * License as published by the Free Software Foundation; either version 2 of * 00010 * the License or (at your option) any later version. This is online at: * 00011 * http://www.fsf.org/copyleft/gpl.html * 00012 * Please send any updates to: fred@gruntose.com * 00013 \*****************************************************************************/ 00014 00015 #include <db_freetds/common.h> 00016 #include <db_freetds/query_handler.h> 00017 #include <db_freetds/login_info.h> 00018 #include <loggers/file_logger.h> 00019 #include <opsystem/application_base.h> 00020 00021 HOOPLE_STARTUP_CODE; 00022 00023 #define LOG(s) STAMPED_EMERGENCY_LOG(program_wide_logger(), s) 00024 00025 const char *DB_SECTION = "test_special_chars"; 00026 00027 database_login_info _global_db_info(DB_SECTION); 00028 00030 00031 #define static_class_name() "t_special_chars" 00032 00033 int main(int argc, char **argv) 00034 { 00035 SET_DEFAULT_CONSOLE_LOGGER; 00036 00037 istring wacky_string_1 = "This has'single quote and wil%dcar_ds"; 00038 istring expect_w1 = "This has''single quote and wil%dcar_ds"; 00039 00040 common_database_support::nerf_special_characters(wacky_string_1, '\\'); 00041 if (expect_w1 != wacky_string_1) 00042 deadly_error(static_class_name(), "test 1", 00043 "did not match expected result"); 00044 00045 istring wacky_string_2 = "'moRe si'ngl''e quotes like'every'wh''r'ree'"; 00046 istring expect_w2 = "''moRe si''ngl''''e quotes like''every''wh''''r''ree''"; 00047 00048 common_database_support::nerf_special_characters(wacky_string_2, '\\'); 00049 if (expect_w2 != wacky_string_2) 00050 deadly_error(static_class_name(), "test 2", 00051 "did not match expected result"); 00052 00053 istring to_print("t_special_chars:: works for those functions tested."); 00054 guards::alert_message(to_print); 00055 00056 return 0; 00057 } 00058
1.5.1