File: sql_parser_test.cpp

package info (click to toggle)
mysql-gui-tools 5.0r14%2BopenSUSE-2.1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 116,956 kB
  • ctags: 48,715
  • sloc: sql: 341,918; pascal: 276,698; ansic: 91,020; cpp: 90,451; objc: 33,236; sh: 29,481; yacc: 10,756; xml: 10,589; java: 10,079; php: 2,806; python: 2,092; makefile: 1,783; perl: 4
file content (108 lines) | stat: -rw-r--r-- 3,231 bytes parent folder | download | duplicates (2)
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

// This file contains common TUT test cases for myx_database_model.c
//
//

//----------------------------------------------------------------------------------------------------------------------

#include "test.h"
//#include "myx_public_interface.h"
#include "myx_sql_parser_public_interface.h"
//#include "myx_library.h"
//#include <fstream>

// Private test data.
BEGIN_TEST_DATA_CLASS(sql_parser_test)
protected:
  Test_connection* connection;
END_TEST_DATA_CLASS

//----------------------------------------------------------------------------------------------------------------------

TEST_MODULE(module_sql_parser_test, "SQL parser test suite");

//----------------------------------------------------------------------------------------------------------------------

TEST_FUNCTION(5)
{
  //connection= test_group_singleton.get_connection();
  //ensure("Server connection", connection != NULL);
}

//----------------------------------------------------------------------------------------------------------------------

/*
*/


static bool test_10_data[5]= {false, false, false, false, true};

int process_split_sql_commands(const char *sql, void *user_data)
{
  static int c= 0;

  static const char *sqls[] = {
    "DROP TABLE IF EXISTS `db1`.`customer's orders`",

    "CREATE TABLE `db1`.`customer's orders` ("
    "`Level` VARCHAR(6) NOT NULL,"
    "`LevelDescription` VARCHAR(255) NULL,"
    "`LevelRank` VARCHAR(6) NULL,"
    "`LevelText` LONGTEXT NULL,"
    "PRIMARY KEY (`Level`)) ENGINE = INNODB",

    "DROP TABLE IF EXISTS `db1`.`customer`",

    "CREATE TABLE `db1`.`customer` (`idcustomer`"
    " INT(10) NOT NULL,`Last Year's Sales` "
    "DECIMAL(19, 4) NULL, PRIMARY KEY (`idcustomer`)) "
    "ENGINE = INNODB"
  };

  if((c >= 0) && (c < 5))
  {
    test_10_data[c]= (strcmp(sqls[c], sql) == 0);
    ++c;
  }
  else
  {
    test_10_data[4]= false;
  }

  return 0;
}

TEST_FUNCTION(10)
{
  MYX_LIB_ERROR error_code= MYX_NO_ERROR;

  static const char *sql1=
    "DROP TABLE IF EXISTS `db1`.`customer's orders`;"
    "CREATE TABLE `db1`.`customer's orders` ("
    "`Level` VARCHAR(6) NOT NULL,"
    "`LevelDescription` VARCHAR(255) NULL,"
    "`LevelRank` VARCHAR(6) NULL,"
    "`LevelText` LONGTEXT NULL,"
    "PRIMARY KEY (`Level`)) ENGINE = INNODB;";


  static const char *sql2=
    "DROP TABLE IF EXISTS `db1`.`customer`;"
    "CREATE TABLE `db1`.`customer` (`idcustomer`"
    " INT(10) NOT NULL,`Last Year's Sales` "
    "DECIMAL(19, 4) NULL, PRIMARY KEY (`idcustomer`)) "
    "ENGINE = INNODB;";


    myx_process_sql_statements(sql1, &process_split_sql_commands, NULL, MYX_SPM_DELIMS_REQUIRED);
    myx_process_sql_statements(sql2, &process_split_sql_commands, NULL, MYX_SPM_DELIMS_REQUIRED);    

  ensure("Parser quote test failed", test_10_data[0] && test_10_data[1] && test_10_data[2] && test_10_data[3] && test_10_data[4]);
}

//----------------------------------------------------------------------------------------------------------------------

END_TESTS;

//----------------------------------------------------------------------------------------------------------------------