File: myx_query.h

package info (click to toggle)
mysql-query-browser 1.2.5beta-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 63,792 kB
  • ctags: 46,485
  • sloc: pascal: 249,299; ansic: 80,111; cpp: 72,467; sh: 25,271; objc: 20,015; yacc: 10,755; java: 9,917; xml: 4,580; php: 2,806; python: 1,566; sql: 1,563; makefile: 1,452; perl: 3
file content (115 lines) | stat: -rw-r--r-- 4,214 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
109
110
111
112
113
114
115
/* Copyright (C) 2003,2004 MySQL AB

   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; either version 2 of the License, or
   (at your option) any later version.

   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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

#ifndef myx_query_h
#define myx_query_h

#ifdef __cplusplus

#include <string>
#include <vector>
#include "myx_const_string.h"

struct Query : public MYX_QUERY
{
  Query();
  ~Query();

  std::string m_sql, m_sql_qithout_comments, m_masked_sql;

  typedef std::vector<const char *> Type_options;
  typedef std::vector<const_string> Type_const_string_options;
  typedef std::vector<MYX_Q_CLAUSE> Type_clauses;
  typedef std::vector<MYX_Q_TABLE>  Type_tables;
  typedef std::vector<MYX_Q_COLUMN>  Type_columns;

  Type_options              m_options;
  Type_const_string_options m_const_string_options;
  Type_clauses              m_clauses;
  Type_tables               m_tables;
  Type_columns              m_columns;

  void prepare_for_delphi();

  const MYX_Q_CLAUSE * get_clause          (MYX_Q_CLAUSE_TYPE c_type)const;
  const MYX_Q_CLAUSE * get_previous_clause (MYX_Q_CLAUSE_TYPE c_type)const;

  MYX_Q_TABLE   * get_table_by_alias(const char * alias,
                                     const char * column= 0);
  MYX_Q_TABLE   * get_first_table();
  MYX_Q_TABLE   * get_table(const char * catalog,
                            const char * schema,
                            const char * table);
  MYX_Q_COLUMN  * get_column(const char * column);

  bool contains_tables_without_aliases()const;
  bool try_to_fix_table_aliases(MYSQL * mysql);
	bool contains_unaliased_table(const char *table_name);

  bool can_contain_clause(MYX_Q_CLAUSE_TYPE clause_type);

  void analyze(MYSQL *mysql, const char *sql);

  MYX_Q_TYPE calc_query_type();
};

// Following functions are listed here for unit-tests.
bool query_is_join(Query *query);

#endif __cplusplus

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

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

#if defined(__WIN__) || defined(_WIN32) || defined(_WIN64)
#include <winsock2.h>
#endif

#define MAX_COMMAND_LINE_LENGTH 80

MYX_PUBLIC_FUNC MYX_QUERY * query_analyze(MYSQL *mysql, const char *sqlcmd);
MYX_PUBLIC_FUNC void query_free(MYX_QUERY *query);

void query_build_clauses(MYX_QUERY *query);
MYX_QUERY * query_get_query_tables(MYSQL *mysql, MYX_QUERY *query);
MYX_QUERY * query_get_query_tables_columns(MYSQL *mysql, MYX_QUERY *query);
MYX_QUERY * query_get_query_columns(MYX_QUERY *query);
MYX_QUERY * query_set_params(MYX_QUERY *query, MYX_STRINGLIST *parameters);

MYX_PUBLIC_FUNC unsigned int query_is_editable(MYX_QUERY *query, int enforce_editable);

MYX_Q_COLUMN * query_add_column(MYX_QUERY *query, MYX_Q_TABLE *q_table, const char *column, char *sql, MYX_Q_CLAUSE_TYPE clause_type);

MYX_STRINGLIST * myx_check_table_relationship(MYSQL *mysql, const char *schema,
                                              const char *table1,
                                              const char *alias1,
                                              const char *table2,
                                              const char *alias2);

char * myx_query_add_table_aliases(MYSQL *mysql, const char *source_sql, const char *new_tablename);
char * myx_query_get_table_alias(MYX_QUERY *query, const char *new_tablename);
char * myx_query_build_from_clauses(MYX_QUERY *query);

#ifdef __cplusplus
}
#endif /* __cplusplus */

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

#endif