1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
/*
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; version 2 of the
* License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#include "testgrt.h"
#include "grt_test_utility.h"
#include "grt/grt_manager.h"
#include "grtpp.h"
#include "grts/structs.h"
#include "grts/structs.workbench.h"
#include "grts/structs.db.mgmt.h"
#include "grts/structs.db.mysql.h"
#include "grts/structs.db.mgmt.h"
#include "cppdbc.h"
#include "backend/db_rev_eng_be.h"
#include "db_mysql_diffsqlgen.h"
#include "diff/diffchange.h"
#include "diff/grtdiff.h"
#include "diff/changeobjects.h"
#include "diff/changelistobjects.h"
#include "db.mysql.sqlparser/src/mysql_sql_parser_fe.h"
#include "wb_helpers.h"
using namespace tut;
struct A
{
std::string _res;
std::string convert(const char *s, GRTManagerTest& grtm, int *err_count= 0)
{
_res= "";
int _err_count= 0;
_err_count= Mysql_sql_parser_fe(grtm.get_app_option_string("SqlMode")).parse_sql_script(s, &process_sql_statement_cb, this);
if (err_count)
*err_count= _err_count;
return _res;
}
private:
static int process_sql_statement_cb(void* user_data, const MyxStatementParser *splitter, const char *sql, const SqlAstNode *tree,
int stmt_begin_lineno, int stmt_begin_line_pos, int stmt_end_lineno, int stmt_end_line_pos,
int err_tok_lineno, int err_tok_line_pos, int err_tok_len, const std::string &err_msg)
{
A &parser_be= *(reinterpret_cast <A *> (user_data));
if (tree)
{
tree->build_sql(parser_be._res);
// std::ofstream("c:/1.xml") << *tree;
}
return (tree==0)? 1 : 0;
}
};
BEGIN_TEST_DATA_CLASS(grtdiff_db_diff_test)
protected:
GRTManagerTest grtm;
END_TEST_DATA_CLASS
TEST_MODULE(grtdiff_db_diff_test, "grtdiff_db_diff_test");
const char* sql= "DELIMITER //\n"
"CREATE TRIGGER `sakila`.`ins_film` AFTER INSERT ON `film` FOR EACH ROW BEGIN\n"
" INSERT INTO film_text (film_id, title, description)\n"
" VALUES (new.film_id, new.title, new.description);\n"
" END//\n";
TEST_FUNCTION(1)
{
const char* sql_after_formatting_change= "DELIMITER //\n CREATE TRIGGER `sakila`.`ins_film` AFTER INSERT ON `film` FOR EACH ROW BEGIN INSERT INTO film_text (film_id, title, description) VALUES (new.film_id, new.title, new.description);\n"
" END//\n";
const char* sql_after_expression_change= "DELIMITER //\n CREATE TRIGGER `sakila`.`ins_film` AFTER INSERT ON `film` FOR EACH ROW BEGIN INSERT INTO film_text (film_id, title, description) VALUES (new.film_id, new.title, 'new.description');\n"
" END//\n";
const char* sql_after_same= sql;
std::string before = A().convert(sql,grtm);
//std::cout << before << std::endl;
//std::cout << A().convert(sql_after_formatting_change) << std::endl;
//std::cout << A().convert(sql_after_expression_change) << std::endl;
//std::cout << A().convert(sql_after_same) << std::endl;
assure(before == A().convert(sql_after_formatting_change,grtm));
assure(before != A().convert(sql_after_expression_change,grtm));
assure(before == A().convert(sql_after_same,grtm));
}
END_TESTS
|