#At file:///net/fimafeng09/export/home/tmp/oleja/mysql/mysql-5.1-telco-7.0-spj-scan-scan/ based on revid:ole.john.aske@stripped
3365 Ole John Aske 2010-11-15 [merge]
Merge from telco-70
removed:
storage/ndb/include/editline/
storage/ndb/include/editline/editline.h
storage/ndb/tools/ndbsql.cpp
storage/ndb/tools/rgrep
modified:
client/mysqltest.cc
sql/ha_ndbcluster.cc
sql/ha_ndbcluster_binlog.cc
sql/ha_ndbcluster_cond.cc
sql/ha_ndbcluster_glue.h
storage/ndb/CMakeLists.txt
storage/ndb/include/Makefile.am
storage/ndb/include/portlib/ndb_prefetch.h
storage/ndb/src/common/util/CMakeLists.txt
storage/ndb/src/kernel/vm/Makefile.am
storage/ndb/src/kernel/vm/testLongSig/testLongSig.cpp
storage/ndb/test/run-test/CMakeLists.txt
storage/ndb/tools/CMakeLists.txt
storage/ndb/tools/ndb_test_platform.cpp
=== modified file 'client/mysqltest.cc'
--- a/client/mysqltest.cc 2010-10-18 06:36:58 +0000
+++ b/client/mysqltest.cc 2010-11-15 10:05:01 +0000
@@ -79,8 +79,11 @@
enum {
OPT_SKIP_SAFEMALLOC=OPT_MAX_CLIENT_OPTION,
OPT_PS_PROTOCOL, OPT_SP_PROTOCOL, OPT_CURSOR_PROTOCOL, OPT_VIEW_PROTOCOL,
- OPT_MAX_CONNECT_RETRIES, OPT_MAX_CONNECTIONS, OPT_MARK_PROGRESS,
- OPT_LOG_DIR, OPT_TAIL_LINES, OPT_RESULT_FORMAT_VERSION
+ OPT_MAX_CONNECT_RETRIES, OPT_MAX_CONNECTIONS,
+ OPT_MARK_PROGRESS, OPT_LOG_DIR, OPT_TAIL_LINES
+#ifndef MCP_RESULT_FORMAT_VERSION
+ ,OPT_RESULT_FORMAT_VERSION
+#endif
};
static int record= 0, opt_sleep= -1;
@@ -93,7 +96,9 @@ const char *opt_logdir= "";
const char *opt_include= 0, *opt_charsets_dir;
static int opt_port= 0;
static int opt_max_connect_retries;
+#ifndef MCP_RESULT_FORMAT_VERSION
static int opt_result_format_version;
+#endif
static int opt_max_connections= DEFAULT_MAX_CONN;
static my_bool opt_compress= 0, silent= 0, verbose= 0;
static my_bool debug_info_flag= 0, debug_check_flag= 0;
@@ -297,13 +302,17 @@ enum enum_commands {
Q_SEND_QUIT, Q_CHANGE_USER, Q_MKDIR, Q_RMDIR,
Q_LIST_FILES, Q_LIST_FILES_WRITE_FILE, Q_LIST_FILES_APPEND_FILE,
Q_SEND_SHUTDOWN, Q_SHUTDOWN_SERVER,
+#ifndef MCP_RESULT_FORMAT_VERSION
Q_RESULT_FORMAT_VERSION,
+#endif
Q_MOVE_FILE, Q_REMOVE_FILES_WILDCARD, Q_SEND_EVAL,
Q_UNKNOWN, /* Unknown command. */
Q_COMMENT, /* Comments, ignored. */
- Q_COMMENT_WITH_COMMAND,
- Q_EMPTY_LINE
+ Q_COMMENT_WITH_COMMAND
+#ifndef MCP_RESULT_FORMAT_VERSION
+ ,Q_EMPTY_LINE
+#endif
};
@@ -397,7 +406,9 @@ const char *command_names[]=
"list_files_append_file",
"send_shutdown",
"shutdown_server",
+#ifndef MCP_RESULT_FORMAT_VERSION
"result_format",
+#endif
"move_file",
"remove_files_wildcard",
"send_eval",
@@ -2231,7 +2242,7 @@ void var_query_set(VAR *var, const char
DBUG_VOID_RETURN;
}
-
+#ifndef MCP_RESULT_FORMAT_VERSION
static void
set_result_format_version(ulong new_version)
{
@@ -2284,7 +2295,7 @@ do_result_format_version(struct st_comma
dynstr_free(&ds_version);
DBUG_VOID_RETURN;
}
-
+#endif
/*
Set variable from the result of a field in a query
@@ -2682,9 +2693,6 @@ static int replace(DYNAMIC_STRING *ds_st
}
-/* where to put this declaration in the file? */
-int regex_replace(DYNAMIC_STRING *ds, char *expr);
-
/*
Execute given command.
@@ -2736,18 +2744,12 @@ void do_exec(struct st_command *command)
#ifdef __WIN__
#ifndef USE_CYGWIN
- {
- char *replaces[]= {
- /* Replace /dev/null with NUL */
- "/\\/dev\\/null/NUL/",
- /* Replace "closed stdout" with non existing output fd */
- "/>&-/>&4/",
- 0
- };
- int i= 0;
- for(;replaces[i];i++)
- regex_replace(&ds_cmd, replaces[i]);
- }
+ /* Replace /dev/null with NUL */
+ while(replace(&ds_cmd, "/dev/null", 9, "NUL", 3) == 0)
+ ;
+ /* Replace "closed stdout" with non existing output fd */
+ while(replace(&ds_cmd, ">&-", 3, ">&4", 3) == 0)
+ ;
#endif
#endif
@@ -4121,7 +4123,11 @@ int do_save_master_pos()
const char latest_applied_binlog_epoch_str[]=
"latest_applied_binlog_epoch=";
if (count)
+#ifndef MCP_BUG58195
my_sleep(100*1000); /* 100ms */
+#else
+ sleep(1);
+#endif
if (mysql_query(mysql, query= "show engine ndb status"))
die("failed in '%s': %d %s", query,
mysql_errno(mysql), mysql_error(mysql));
@@ -4210,8 +4216,12 @@ int do_save_master_pos()
count++;
if (latest_handled_binlog_epoch >= start_epoch)
do_continue= 0;
+#ifndef MCP_BUG58195
else if (count > 300) /* 30s */
- {
+#else
+ else if (count > 30)
+#endif
+ {
break;
}
mysql_free_result(res);
@@ -5574,7 +5584,10 @@ my_bool end_of_query(int c)
int read_line(char *buf, int size)
{
- char c, UNINIT_VAR(last_quote), last_char= 0;
+ char c, UNINIT_VAR(last_quote);
+#ifndef MCP_RESULT_FORMAT_VERSION
+ char last_char= 0;
+#endif
char *p= buf, *buf_end= buf + size - 1;
int skip_char= 0;
enum {R_NORMAL, R_Q, R_SLASH_IN_Q,
@@ -5672,8 +5685,12 @@ int read_line(char *buf, int size)
}
else if (my_isspace(charset_info, c))
{
+#ifdef MCP_RESULT_FORMAT_VERSION
+ /* Skip all space at begining of line */
+#endif
if (c == '\n')
{
+#ifndef MCP_RESULT_FORMAT_VERSION
if (last_char == '\n')
{
/* Two new lines in a row, return empty line */
@@ -5682,14 +5699,15 @@ int read_line(char *buf, int size)
*p= 0;
DBUG_RETURN(0);
}
-
+#endif
/* Query hasn't started yet */
start_lineno= cur_file->lineno;
DBUG_PRINT("info", ("Query hasn't started yet, start_lineno: %d",
start_lineno));
}
-
+#ifndef MCP_RESULT_FORMAT_VERSION
/* Skip all space at begining of line */
+#endif
skip_char= 1;
}
else if (end_of_query(c))
@@ -5730,8 +5748,9 @@ int read_line(char *buf, int size)
}
+#ifndef MCP_RESULT_FORMAT_VERSION
last_char= c;
-
+#endif
if (!skip_char)
{
/* Could be a multibyte character */
@@ -5941,10 +5960,12 @@ int read_command(struct st_command** com
DBUG_RETURN(1);
}
+#ifndef MCP_RESULT_FORMAT_VERSION
if (opt_result_format_version == 1)
+#endif
convert_to_format_v1(read_command_buf);
- DBUG_PRINT("info", ("query: '%s'", read_command_buf));
+ DBUG_PRINT("info", ("query: %s", read_command_buf));
if (*p == '#')
{
command->type= Q_COMMENT;
@@ -5954,10 +5975,12 @@ int read_command(struct st_command** com
command->type= Q_COMMENT_WITH_COMMAND;
p+= 2; /* Skip past -- */
}
+#ifndef MCP_RESULT_FORMAT_VERSION
else if (*p == '\n')
{
command->type= Q_EMPTY_LINE;
}
+#endif
/* Skip leading spaces */
while (*p && my_isspace(charset_info, *p))
@@ -6058,11 +6081,13 @@ static struct my_option my_long_options[
{"result-file", 'R', "Read/store result from/in this file.",
&result_file_name, &result_file_name, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+#ifndef MCP_RESULT_FORMAT_VERSION
{"result-format-version", OPT_RESULT_FORMAT_VERSION,
"Version of the result file format to use",
(uchar**) &opt_result_format_version,
(uchar**) &opt_result_format_version, 0,
GET_INT, REQUIRED_ARG, 1, 1, 2, 0, 0, 0},
+#endif
{"server-arg", 'A', "Send option value to embedded server as a parameter.",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"server-file", 'F', "Read embedded server arguments from file.",
@@ -6267,9 +6292,11 @@ get_one_option(int optid, const struct m
sf_malloc_quick=1;
#endif
break;
+#ifndef MCP_RESULT_FORMAT_VERSION
case OPT_RESULT_FORMAT_VERSION:
set_result_format_version(opt_result_format_version);
break;
+#endif
case 'V':
print_version();
exit(0);
@@ -8177,7 +8204,9 @@ int main(int argc, char **argv)
case Q_MOVE_FILE: do_move_file(command); break;
case Q_CHMOD_FILE: do_chmod_file(command); break;
case Q_PERL: do_perl(command); break;
+#ifndef MCP_RESULT_FORMAT_VERSION
case Q_RESULT_FORMAT_VERSION: do_result_format_version(command); break;
+#endif
case Q_DELIMITER:
do_delimiter(command);
break;
@@ -8302,7 +8331,10 @@ int main(int argc, char **argv)
do_sync_with_master2(command, 0);
break;
}
- case Q_COMMENT:
+#ifdef MCP_RESULT_FORMAT_VERSION
+ case Q_COMMENT: /* Ignore row */
+ command->last_argument= command->end;
+#else
{
const char* p= command->query;
command->last_argument= command->end;
@@ -8333,6 +8365,7 @@ int main(int argc, char **argv)
break;
dynstr_append(&ds_res, "\n");
+#endif
break;
case Q_PING:
handle_command_error(command, mysql_ping(&cur_con->mysql));
@@ -9014,31 +9047,15 @@ void do_get_replace_regex(struct st_comm
command->last_argument= command->end;
}
-/* where to put these functions in the file? */
-void free_regex(struct st_replace_regex* r)
-{
- delete_dynamic(&r->regex_arr);
- my_free(r->even_buf,MYF(MY_ALLOW_ZERO_PTR));
- my_free(r->odd_buf,MYF(MY_ALLOW_ZERO_PTR));
- my_free(r,MYF(0));
-}
-
-/* where to put these functions in the file? */
-int regex_replace(DYNAMIC_STRING *ds, char *expr)
-{
- struct st_replace_regex* r= init_replace_regex(expr);
- int rv= multi_reg_replace(r, ds->str);
- dynstr_set(ds, r->buf);
- free_regex(r);
- return rv;
-}
-
void free_replace_regex()
{
if (glob_replace_regex)
{
- free_regex(glob_replace_regex);
- glob_replace_regex= 0;
+ delete_dynamic(&glob_replace_regex->regex_arr);
+ my_free(glob_replace_regex->even_buf,MYF(MY_ALLOW_ZERO_PTR));
+ my_free(glob_replace_regex->odd_buf,MYF(MY_ALLOW_ZERO_PTR));
+ my_free(glob_replace_regex,MYF(0));
+ glob_replace_regex=0;
}
}
=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc 2010-11-15 10:26:48 +0000
+++ b/sql/ha_ndbcluster.cc 2010-11-15 11:08:25 +0000
@@ -9521,6 +9521,9 @@ static int create_ndb_column(THD *thd,
col.setAutoIncrement(FALSE);
#ifndef NDB_WITHOUT_COLUMN_FORMAT
+ DBUG_PRINT("info", ("storage: %u format: %u ",
+ field->field_storage_type(),
+ field->column_format()));
switch (field->field_storage_type()) {
case(HA_SM_DEFAULT):
default:
@@ -9765,7 +9768,9 @@ int ha_ndbcluster::create(const char *na
NDBDICT *dict= ndb->getDictionary();
Ndb_table_guard ndbtab_g(dict);
+#ifndef NDB_WITHOUT_TABLESPACE_IN_FRM
DBUG_PRINT("info", ("Tablespace %s,%s", form->s->tablespace, create_info->tablespace));
+#endif
table= form;
if (create_from_engine)
{
@@ -9905,11 +9910,8 @@ int ha_ndbcluster::create(const char *na
for (i= 0; i < form->s->fields; i++)
{
Field *field= form->field[i];
- DBUG_PRINT("info", ("name: %s type: %u storage: %u format: %u "
- "pack_length: %d",
+ DBUG_PRINT("info", ("name: %s, type: %u, pack_length: %d",
field->field_name, field->real_type(),
- field->field_storage_type(),
- field->column_format(),
field->pack_length()));
if ((my_errno= create_ndb_column(thd, col, field, create_info)))
goto abort;
@@ -13229,7 +13231,7 @@ int handle_trailing_share(THD *thd, NDB_
table_list.db= share->db;
table_list.alias= table_list.table_name= share->table_name;
if (have_lock_open)
- safe_mutex_assert_owner(&LOCK_open);
+ mysql_mutex_assert_owner(&LOCK_open);
else
mysql_mutex_lock(&LOCK_open);
close_cached_tables(thd, &table_list, TRUE, FALSE, FALSE);
=== modified file 'sql/ha_ndbcluster_binlog.cc'
--- a/sql/ha_ndbcluster_binlog.cc 2010-11-10 10:31:20 +0000
+++ b/sql/ha_ndbcluster_binlog.cc 2010-11-15 09:18:27 +0000
@@ -279,9 +279,11 @@ static void run_query(THD *thd, char *bu
DBUG_PRINT("query", ("%s", thd->query()));
DBUG_ASSERT(!thd->in_sub_stmt);
- DBUG_ASSERT(!thd->prelocked_mode);
#if MYSQL_VERSION_ID >= 50501
+
+ DBUG_ASSERT(!thd->locked_tables_mode);
+
{
Parser_state parser_state;
if (!parser_state.init(thd, thd->query(), thd->query_length()))
@@ -316,6 +318,9 @@ static void run_query(THD *thd, char *bu
*/
thd->stmt_da->reset_diagnostics_area();
#else
+
+ DBUG_ASSERT(!thd->prelocked_mode);
+
const char* found_semicolon= NULL;
mysql_parse(thd, thd->query(), thd->query_length(), &found_semicolon);
@@ -401,7 +406,7 @@ ndbcluster_binlog_open_table(THD *thd, N
TABLE *table= event_data->table=
(TABLE*)alloc_root(&event_data->mem_root, sizeof(TABLE));
- safe_mutex_assert_owner(&LOCK_open);
+ mysql_mutex_assert_owner(&LOCK_open);
init_tmp_table_share(thd, table_share, share->db, 0, share->table_name,
share->key);
if ((error= open_table_def(thd, table_share, 0)) ||
@@ -2348,7 +2353,7 @@ end:
pthread_mutex_lock(&ndb_schema_object->mutex);
if (have_lock_open)
{
- safe_mutex_assert_owner(&LOCK_open);
+ mysql_mutex_assert_owner(&LOCK_open);
mysql_mutex_unlock(&LOCK_open);
}
while (1)
@@ -5081,7 +5086,7 @@ ndbcluster_handle_drop_table(THD *thd, N
#ifdef SYNC_DROP_
thd->proc_info= "Syncing ndb table schema operation and binlog";
pthread_mutex_lock(&share->mutex);
- safe_mutex_assert_owner(&LOCK_open);
+ mysql_mutex_assert_owner(&LOCK_open);
mysql_mutex_unlock(&LOCK_open);
int max_timeout= DEFAULT_SYNC_TIMEOUT;
while (share->op)
=== modified file 'sql/ha_ndbcluster_cond.cc'
--- a/sql/ha_ndbcluster_cond.cc 2010-11-15 10:26:48 +0000
+++ b/sql/ha_ndbcluster_cond.cc 2010-11-15 11:08:25 +0000
@@ -1530,12 +1530,11 @@ int ha_ndbcluster_cond::generate_scan_fi
const KEY_PART_INFO* key_part=key_info->key_part;
if (key_part->null_bit != 0) // nullable (must be)
{
- const Field* field=key_part->field;
const uchar* ptr= start_key->key;
if (ptr[0] != 0) // null (in "null < x")
{
DBUG_PRINT("info", ("Generating ISNOTNULL filter for nullable %s",
- field->field_name));
+ key_part->field->field_name));
if (filter.isnotnull(key_part->fieldnr-1) == -1)
DBUG_RETURN(1);
break;
=== modified file 'sql/ha_ndbcluster_glue.h'
--- a/sql/ha_ndbcluster_glue.h 2010-11-10 11:37:55 +0000
+++ b/sql/ha_ndbcluster_glue.h 2010-11-15 09:15:27 +0000
@@ -188,6 +188,12 @@ int mysql_mutex_unlock(mysql_mutex_t* mu
return pthread_mutex_unlock(mutex);
}
+static inline
+void mysql_mutex_assert_owner(mysql_mutex_t* mutex)
+{
+ return safe_mutex_assert_owner(mutex);
+}
+
typedef pthread_cond_t mysql_cond_t;
static inline
=== modified file 'storage/ndb/CMakeLists.txt'
--- a/storage/ndb/CMakeLists.txt 2010-11-15 10:26:48 +0000
+++ b/storage/ndb/CMakeLists.txt 2010-11-15 11:08:25 +0000
@@ -126,5 +126,13 @@ IF(EXISTS ${CMAKE_SOURCE_DIR}/storage/my
ELSE()
# New plugin support, cross-platform
MYSQL_ADD_PLUGIN(ndbcluster ${NDBCLUSTER_SOURCES} STORAGE_ENGINE
- DEFAULT MODULE_OUTPUT_NAME ha_ndb LINK_LIBRARIES ndbclient)
+ DEFAULT STATIC_ONLY RECOMPILE_FOR_EMBEDDED LINK_LIBRARIES ndbclient)
+
+ IF (NOT MCP_BUG58158)
+ IF(WITH_EMBEDDED_SERVER)
+ # Kludge libndbclient into variable used when creating libmysqld
+ SET (MYSQLD_STATIC_PLUGIN_LIBS ${MYSQLD_STATIC_PLUGIN_LIBS}
+ ndbclient CACHE INTERNAL "" FORCE)
+ ENDIF()
+ ENDIF()
ENDIF()
=== modified file 'storage/ndb/include/Makefile.am'
--- a/storage/ndb/include/Makefile.am 2010-11-10 08:01:00 +0000
+++ b/storage/ndb/include/Makefile.am 2010-11-15 11:08:25 +0000
@@ -60,6 +60,6 @@ noinst_HEADERS = \
ndb_global.h \
ndb_net.h
-EXTRA_DIST = debugger editline kernel logger mgmcommon \
+EXTRA_DIST = debugger kernel logger mgmcommon \
portlib transporter util CMakeLists.txt ndb_config.h.in
=== removed directory 'storage/ndb/include/editline'
=== removed file 'storage/ndb/include/editline/editline.h'
--- a/storage/ndb/include/editline/editline.h 2009-05-26 18:53:34 +0000
+++ b/storage/ndb/include/editline/editline.h 1970-01-01 00:00:00 +0000
@@ -1,40 +0,0 @@
-/*
- Copyright (C) 2003 MySQL AB
- All rights reserved. Use is subject to license terms.
-
- 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
-*/
-
-/* $Id: editline.h,v 1.1 2002/12/11 13:53:46 hin Exp $ */
-
-/*
- * Public include file for editline, to be included instead of readline.h
- */
-
-#ifndef __EDITLINE_H_INCLUDED__
-#define __EDITLINE_H_INCLUDED__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern char *readline(const char *);
-extern void add_history(char *);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* !__EDITLINE_H_INCLUDED__ */
-
=== modified file 'storage/ndb/include/portlib/ndb_prefetch.h'
--- a/storage/ndb/include/portlib/ndb_prefetch.h 2010-11-11 15:03:47 +0000
+++ b/storage/ndb/include/portlib/ndb_prefetch.h 2010-11-15 08:44:24 +0000
@@ -56,7 +56,7 @@ void NDB_PREFETCH_WRITE(void* addr)
#elif defined(USE_SUN_PREFETCH)
sun_prefetch_write_once(addr);
#elif defined(USE_SPARC_PREFETCH)
- sun_prefetch_write_once(addr);
+ sparc_prefetch_write_once(addr);
#else
(void)addr;
#endif
=== modified file 'storage/ndb/src/common/util/CMakeLists.txt'
--- a/storage/ndb/src/common/util/CMakeLists.txt 2010-11-11 15:08:52 +0000
+++ b/storage/ndb/src/common/util/CMakeLists.txt 2010-11-11 16:14:33 +0000
@@ -19,7 +19,6 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOUR
${CMAKE_BINARY_DIR}/storage/ndb/include
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/mysys
- ${ZLIB_INCLUDE_DIR}
${CMAKE_SOURCE_DIR}/storage/ndb/include
${CMAKE_SOURCE_DIR}/storage/ndb/include/util
${CMAKE_SOURCE_DIR}/storage/ndb/include/portlib
=== modified file 'storage/ndb/src/kernel/vm/Makefile.am'
--- a/storage/ndb/src/kernel/vm/Makefile.am 2010-09-23 11:55:42 +0000
+++ b/storage/ndb/src/kernel/vm/Makefile.am 2010-11-15 11:08:25 +0000
@@ -14,11 +14,6 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-#SUBDIRS = testCopy testDataBuffer testSimplePropertiesSection
-#ifneq ($(USE_EDITLINE), N)
-#DIRS += testLongSig
-#endif
-
noinst_LIBRARIES = libkernel.a libsched.a
EXTRA_LIBRARIES= libsched_mt.a
=== modified file 'storage/ndb/src/kernel/vm/testLongSig/testLongSig.cpp'
--- a/storage/ndb/src/kernel/vm/testLongSig/testLongSig.cpp 2009-05-27 15:21:45 +0000
+++ b/storage/ndb/src/kernel/vm/testLongSig/testLongSig.cpp 2010-11-15 09:39:07 +0000
@@ -19,7 +19,7 @@
#include <ndb_global.h>
#include <NdbApi.hpp>
-#include <editline/editline.h>
+#include <readline/readline.h>
#include <../../ndbapi/SignalSender.hpp>
void
=== modified file 'storage/ndb/test/run-test/CMakeLists.txt'
--- a/storage/ndb/test/run-test/CMakeLists.txt 2010-08-02 11:49:11 +0000
+++ b/storage/ndb/test/run-test/CMakeLists.txt 2010-11-11 17:26:34 +0000
@@ -30,7 +30,9 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/storage/ndb/include/mgmcommon
${CMAKE_SOURCE_DIR}/sql
)
-
+IF(NOT WIN32)
+ ADD_DEFINITIONS(-DDEFAULT_PREFIX=\"${CMAKE_INSTALL_PREFIX}\")
+ENDIF()
ADD_EXECUTABLE(atrt main.cpp setup.cpp files.cpp db.cpp command.cpp)
TARGET_LINK_LIBRARIES(atrt ndbNDBT ndbclient dbug mysys strings mysqlclient)
=== modified file 'storage/ndb/tools/CMakeLists.txt'
--- a/storage/ndb/tools/CMakeLists.txt 2010-11-11 13:19:26 +0000
+++ b/storage/ndb/tools/CMakeLists.txt 2010-11-15 10:32:58 +0000
@@ -15,12 +15,9 @@
INCLUDE(${CMAKE_SOURCE_DIR}/storage/ndb/config/type_ndbapitools.cmake)
-INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR}
- ${CMAKE_SOURCE_DIR}/storage/ndb/src/ndbapi
- ${CMAKE_SOURCE_DIR}/storage/ndb/include/debugger
-)
+INCLUDE_DIRECTORIES(
+ ${CMAKE_SOURCE_DIR}/storage/ndb/src/ndbapi)
-ADD_EXECUTABLE(ndb_test_platform ndb_test_platform.cpp)
ADD_EXECUTABLE(ndb_waiter waiter.cpp)
TARGET_LINK_LIBRARIES(ndb_waiter ndbportlib ndbNDBT)
ADD_EXECUTABLE(ndb_drop_table drop_tab.cpp)
@@ -63,3 +60,9 @@ ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_SOUR
ADD_CUSTOM_TARGET(ndbinfo_sql_run ALL
DEPENDS ${PROJECT_SOURCE_DIR}/storage/ndb/tools/ndbinfo.sql)
+
+IF (MYSQL_VERSION_ID VERSION_LESS "50501")
+ # Don't build or install this program anymore in 5.5+
+ ADD_EXECUTABLE(ndb_test_platform ndb_test_platform.cpp)
+ENDIF()
+
=== modified file 'storage/ndb/tools/ndb_test_platform.cpp'
--- a/storage/ndb/tools/ndb_test_platform.cpp 2010-10-07 05:39:39 +0000
+++ b/storage/ndb/tools/ndb_test_platform.cpp 2010-11-15 09:27:19 +0000
@@ -68,6 +68,8 @@ int test_snprintf(const char * fmt, int
int
main(void)
{
+
+ printf("ndb_test_platform - tests for snprintf and pointer size\n");
/*
* Test BaseString::snprintf
*/
=== removed file 'storage/ndb/tools/ndbsql.cpp'
--- a/storage/ndb/tools/ndbsql.cpp 2009-05-26 18:53:34 +0000
+++ b/storage/ndb/tools/ndbsql.cpp 1970-01-01 00:00:00 +0000
@@ -1,959 +0,0 @@
-/*
- Copyright (C) 2003 MySQL AB
- All rights reserved. Use is subject to license terms.
-
- 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
-*/
-
-/*******************************************************************************
- * NDB Cluster NDB SQL -- A simple SQL Command-line Interface
- *
- ******************************************************************************/
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#ifdef NDB_MACOSX
-#include <stdlib.h>
-#else
-#include <malloc.h>
-#endif
-#include <errno.h>
-#include <editline/editline.h>
-#include <NdbOut.hpp>
-#include <ctype.h>
-#include <wctype.h>
-
-#ifndef SQL_BLOB
-#define SQL_BLOB 30
-#endif
-#ifndef SQL_CLOB
-#define SQL_CLOB 40
-#endif
-
-/**************************************************************************
- * ------------------------------------------------------------------------
- * MODULE: Readline and string handling
- * ------------------------------------------------------------------------
- **************************************************************************/
-#define MAXBUF 2048
-static char* s_readBuf;
-static int s_bufSize = MAXBUF;
-
-static char*
-readSQL_File(FILE* inputFile)
-{
- int c;
- int i = 0;
- if (feof(inputFile))
- return 0;
- while ((c = getc(inputFile)) != EOF) {
- if (i == s_bufSize-1) {
- s_bufSize *= 2;
- s_readBuf = (char*)realloc(s_readBuf, s_bufSize);
- }
- s_readBuf[i] = c;
- if (c == '\n')
- break;
- i++;
- }
- s_readBuf[i] = 0;
- return s_readBuf;
-}
-
-static char*
-readline_gets(const char* prompt, bool batchMode, FILE* inputFile)
-{
- static char *line_read = (char *)NULL;
-
- // Disable the default file-name completion action of TAB
- // rl_bind_key ('\t', rl_insert);
-
- if (batchMode)
- /* Read one line from a file. */
- line_read = readSQL_File(inputFile);
- else
- /* Get a line from the user. */
- line_read = readline(prompt);
-
- /* If the line has any text in it, save it in the history. */
- if (!batchMode)
- if (line_read && *line_read) add_history(line_read);
-
- return (line_read);
-}
-
-#ifdef NDB_WIN32
-extern "C"
-{
- char* readline(const char* prompt)
- {
- fputs(prompt, stdout);
- return fgets(s_readBuf, MAXBUF, stdin);
- }
- void add_history(char*)
- {
- }
-}
-#endif
-
-bool emptyString(const char* s) {
- if (s == NULL) {
- return true;
- }
-
- for (unsigned int i = 0; i < strlen(s); ++i) {
- if (! isspace(s[i])) {
- return false;
- }
- }
-
- return true;
-}
-
-/**************************************************************************
- * ------------------------------------------------------------------------
- * MODULE: ODBC Handling
- * ------------------------------------------------------------------------
- **************************************************************************/
-
-#include <sqlext.h>
-#include <stdio.h>
-#include <string.h>
-#ifdef NDB_MACOSX
-#include <stdlib.h>
-#else
-#include <malloc.h>
-#endif
-/**
- * In the case where the user types a SELECT statement,
- * the function fetches and displays all rows of the result set.
- *
- * This example illustrates the use of GetDiagField to identify the
- * type of SQL statement executed and, for SQL statements where the
- * row count is defined on all implementations, the use of GetDiagField
- * to obtain the row count.
- */
-#define MAXCOLS 100
-#undef max
-#define max(a,b) ((a)>(b)?(a):(b))
-
-#define MAX_MESSAGE 500
-
-void getDiag(SQLSMALLINT type, SQLHANDLE handle, unsigned k, unsigned count)
-{
- char message[MAX_MESSAGE];
- char state[6];
- SQLINTEGER native;
-
- SQLSMALLINT length = -1;
- memset(message, 0, MAX_MESSAGE);
- int ret = SQLGetDiagRec(type, handle, k, (SQLCHAR*)state,
- &native, (SQLCHAR*)message, MAX_MESSAGE, &length);
- if (ret == SQL_NO_DATA) {
- ndbout << "No error diagnostics available" << endl;
- return;
- }
- ndbout << message << endl;
-
- if (k <= count && ret != SQL_SUCCESS)
- ndbout_c("SQLGetDiagRec %d of %d: return %d != SQL_SUCCESS",
- k, count, (int)ret);
- if (k <= count && (SQLSMALLINT) strlen(message) != length)
- ndbout_c("SQLGetDiagRec %d of %d: message length %d != %d",
- k, count, strlen(message), length);
- if (k > count && ret != SQL_NO_DATA)
- ndbout_c("SQLGetDiagRec %d of %d: return %d != SQL_NO_DATA",
- k, count, (int)ret);
-}
-
-int print_err(SQLSMALLINT handletype, SQLHDBC hdbc) {
- getDiag(handletype, hdbc, 1, 1);
-
- return -1;
-}
-
-
-/***************************************************************
- * The following functions are given for completeness, but are
- * not relevant for understanding the database processing
- * nature of CLI
- ***************************************************************/
-#define MAX_NUM_PRECISION 15
-/*#define max length of char string representation of no. as:
-= max(precision) + leading sign +E +expsign + max exp length
-= 15 +1 +1 +1 +2
-= 15 +5
-*/
-#define MAX_NUM_STRING_SIZE (MAX_NUM_PRECISION + 5)
-
-int build_indicator_message(SQLCHAR *errmsg, SQLPOINTER *data,
- SQLINTEGER collen, SQLINTEGER *outlen,
- SQLSMALLINT colnum) {
- if (*outlen == SQL_NULL_DATA) {
- (void)strcpy((char *)data, "NULL");
- *outlen=4;
- } else {
- sprintf((char *)errmsg+strlen((char *)errmsg),
- "%ld chars truncated, col %d\n", *outlen-collen+1,
- colnum);
- *outlen=255;
- }
- return 0;
-}
-
-
-SQLINTEGER display_length(SQLSMALLINT coltype, SQLINTEGER collen,
- SQLCHAR *colname) {
- switch (coltype) {
- case SQL_VARCHAR:
- case SQL_CHAR:
- case SQL_VARBINARY:
- case SQL_BINARY:
- case SQL_BLOB:
- case SQL_CLOB:
- case SQL_BIT:
- //case SQL_REF:
- //case SQL_BIT_VARYING:
- return(max(collen,(SQLINTEGER) strlen((char *)colname))+1);
- case SQL_FLOAT:
- case SQL_DOUBLE:
- case SQL_NUMERIC:
- case SQL_REAL:
- case SQL_DECIMAL:
- return(max(MAX_NUM_STRING_SIZE,strlen((char *)colname))+1);
- case SQL_TYPE_DATE:
- case SQL_TYPE_TIME:
- //case SQL_TYPE_TIME_WITH_TIMEZONE:
- case SQL_TYPE_TIMESTAMP:
- //case SQL_TYPE_TIMESTAMP_WITH_TIMEZONE:
- case SQL_INTERVAL_YEAR:
- case SQL_INTERVAL_MONTH:
- case SQL_INTERVAL_DAY:
- case SQL_INTERVAL_HOUR:
- case SQL_INTERVAL_MINUTE:
- case SQL_INTERVAL_SECOND:
- case SQL_INTERVAL_YEAR_TO_MONTH:
- case SQL_INTERVAL_DAY_TO_HOUR:
- case SQL_INTERVAL_DAY_TO_MINUTE:
- case SQL_INTERVAL_DAY_TO_SECOND:
- case SQL_INTERVAL_HOUR_TO_MINUTE:
- case SQL_INTERVAL_HOUR_TO_SECOND:
- case SQL_INTERVAL_MINUTE_TO_SECOND:
- return(max(collen,(SQLINTEGER) strlen((char *)colname))+1);
- case SQL_INTEGER:
- //case SQL_BLOB_LOCATOR:
- //case SQL_CLOB_LOCATOR:
- //case SQL_UDT_LOCATOR:
- //case SQL_ARRAY_LOCATOR:
- return(max(11,strlen((char *)colname))+1);
- case SQL_BIGINT:
- return(max(21,strlen((char *)colname))+1);
- case SQL_SMALLINT:
- return(max(5,strlen((char *)colname))+1);
- default:
- (void)printf("Unknown datatype, %d\n", coltype);
- return(0);
- }
-}
-
-struct Con {
- const char* dsn;
- SQLHENV henv;
- SQLHDBC hdbc;
- Con(const char* _dsn) :
- dsn(_dsn), henv(SQL_NULL_HANDLE), hdbc(SQL_NULL_HANDLE) {}
-};
-
-static int
-do_connect(Con& con)
-{
- int ret;
-
- // allocate an environment handle
- ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &con.henv);
- if (ret != SQL_SUCCESS)
- return -1;
-
- // set odbc version (required)
- ret = SQLSetEnvAttr(con.henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, 0);
- if (ret != SQL_SUCCESS)
- return -1;
-
- // allocate a connection handle
- ret = SQLAllocHandle(SQL_HANDLE_DBC, con.henv, &con.hdbc);
- if (ret != SQL_SUCCESS)
- return -1;
-
- // connect to database
- SQLCHAR szConnStrOut[256];
- SQLSMALLINT cbConnStrOut;
- ret = SQLDriverConnect(con.hdbc, 0, (SQLCHAR*)con.dsn, SQL_NTS,
- szConnStrOut, sizeof(szConnStrOut), &cbConnStrOut, SQL_DRIVER_COMPLETE);
- if (ret != SQL_SUCCESS) {
- ndbout << "Connection failure: Could not connect to database" << endl;
- print_err(SQL_HANDLE_DBC, con.hdbc);
- return -1;
- }
-
- return 0;
-}
-
-static int
-do_disconnect(Con& con)
-{
- // disconnect from database
- SQLDisconnect(con.hdbc);
-
- // free connection handle
- SQLFreeHandle(SQL_HANDLE_DBC, con.hdbc);
- con.hdbc = SQL_NULL_HANDLE;
-
- // free environment handle
- SQLFreeHandle(SQL_HANDLE_ENV, con.henv);
- con.henv = SQL_NULL_HANDLE;
-
- return 0;
-}
-
-static int
-get_autocommit(Con& con)
-{
- int ret;
- SQLUINTEGER v;
- ret = SQLGetConnectAttr(con.hdbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)&v, SQL_IS_UINTEGER, 0);
- if (ret != SQL_SUCCESS) {
- ndbout << "Get autocommit failed" << endl;
- print_err(SQL_HANDLE_DBC, con.hdbc);
- return -1;
- }
- return v;
-}
-
-static int
-set_autocommit(Con& con, SQLUINTEGER v)
-{
- int ret;
- ret = SQLSetConnectAttr(con.hdbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)v, SQL_IS_UINTEGER);
- if (ret != SQL_SUCCESS) {
- ndbout << "Set autocommit failed" << endl;
- print_err(SQL_HANDLE_DBC, con.hdbc);
- return -1;
- }
- return 0;
-}
-
-static int
-do_commit(Con& con)
-{
- int ret = SQLEndTran(SQL_HANDLE_DBC, con.hdbc, SQL_COMMIT);
- if (ret != SQL_SUCCESS) {
- ndbout << "Commit failed" << endl;
- print_err(SQL_HANDLE_DBC, con.hdbc);
- return -1;
- }
- return 0;
-}
-
-static int
-do_rollback(Con& con)
-{
- int ret = SQLEndTran(SQL_HANDLE_DBC, con.hdbc, SQL_ROLLBACK);
- if (ret != SQL_SUCCESS) {
- ndbout << "Rollback failed" << endl;
- print_err(SQL_HANDLE_DBC, con.hdbc);
- return -1;
- }
- return 0;
-}
-
-static int
-do_stmt(Con& con, const char *sqlstr)
-{
- SQLHSTMT hstmt;
- SQLCHAR errmsg[256];
- SQLCHAR colname[32];
- SQLSMALLINT coltype;
- SQLSMALLINT colnamelen;
- SQLSMALLINT nullable;
- SQLUINTEGER collen[MAXCOLS];
- SQLSMALLINT scale;
- SQLINTEGER outlen[MAXCOLS];
- SQLCHAR *data[MAXCOLS];
- SQLSMALLINT nresultcols = 0;
- SQLINTEGER rowcount;
- SQLINTEGER stmttype;
- SQLRETURN rc;
-
- /* allocate a statement handle */
- SQLAllocHandle(SQL_HANDLE_STMT, con.hdbc, &hstmt);
-
- /* execute the SQL statement */
- rc = SQLExecDirect(hstmt, (SQLCHAR*)sqlstr, SQL_NTS);
- if (rc == SQL_ERROR) {
- ndbout << "Operation failed" << endl;
- print_err(SQL_HANDLE_STMT, hstmt);
- return -1;
- }
- if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO && rc != SQL_NO_DATA_FOUND) {
- ndbout << "Operation returned unknown code " << rc << endl;
- return -1;
- }
-
- /* see what kind of statement it was */
- SQLGetDiagField(SQL_HANDLE_STMT, hstmt, 0,
- SQL_DIAG_DYNAMIC_FUNCTION_CODE,
- (SQLPOINTER)&stmttype, SQL_IS_INTEGER, (SQLSMALLINT *)NULL);
-
- switch (stmttype) {
- /* SELECT statement */
- case SQL_DIAG_SELECT_CURSOR:
- /* determine number of result columns */
- SQLNumResultCols(hstmt, &nresultcols);
-
- /***********************
- * Display column names
- ***********************/
- /* Print vertical divider */
- printf("|");
- for (int i=0; i<nresultcols; i++) {
- SQLDescribeCol(hstmt, i+1, colname, sizeof(colname),
- &colnamelen, &coltype, &collen[i], &scale, &nullable);
- collen[i] = display_length(coltype, collen[i], colname);
- for (SQLUINTEGER j=0; j<collen[i]; j++) printf("-");
- printf("--+");
- }
- printf("\n");
-
- printf("|");
- for (int i=0; i<nresultcols; i++) {
- SQLDescribeCol(hstmt, i+1, colname, sizeof(colname),
- &colnamelen, &coltype, &collen[i], &scale, &nullable);
-
- /* assume there is a display_length function which
- computes correct length given the data type */
- collen[i] = display_length(coltype, collen[i], colname);
- (void)printf(" %*.*s |", (int)collen[i], (int)collen[i], (char *)colname);
-
- /* allocate memory to bind column */
- data[i] = (SQLCHAR *) malloc(collen[i]);
- if (data[i] == NULL) {
- ndbout << "Failed to allocate malloc memory in NDB SQL program"
- << endl;
- exit(-1);
- }
-
- /* bind columns to program vars, converting all types to CHAR */
- SQLBindCol(hstmt, i+1, SQL_C_CHAR, data[i], collen[i], &outlen[i]);
- }
- printf("\n");
-
- /* Print vertical divider */
- printf("|");
- for (int i=0; i<nresultcols; i++) {
- SQLDescribeCol(hstmt, i+1, colname, sizeof(colname),
- &colnamelen, &coltype, &collen[i], &scale, &nullable);
- collen[i] = display_length(coltype, collen[i], colname);
- for (SQLUINTEGER j=0; j<collen[i]; j++) printf("-");
- printf("--+");
- }
- printf("\n");
-
- /**********************
- * Display result rows
- **********************/
- {
- int no_of_rows_fetched=0;
- while (1) {
- rc=SQLFetch(hstmt);
- errmsg[0] = '\0';
- if (rc == SQL_ERROR) {
- print_err(SQL_HANDLE_STMT, hstmt);
- break;
- }
- if (rc == SQL_NO_DATA) break;
- if (rc == SQL_SUCCESS) {
- printf("|");
- for (int i=0; i<nresultcols; i++) {
- if (outlen[i] == SQL_NULL_DATA
- || outlen[i] >= (SQLINTEGER) collen[i])
- build_indicator_message(errmsg,
- (SQLPOINTER *)data[i], collen[i],
- &outlen[i], i);
- (void)printf(" %*.*s |", (int)collen[i], (int)collen[i],
- (char *)data[i]);
- }
- /* print any truncation messages */
- (void)printf("\n%s", (char *)errmsg);
- } else if (rc == SQL_SUCCESS_WITH_INFO) {
- printf("|");
- for (int i=0; i<nresultcols; i++) {
- if (outlen[i] == SQL_NULL_DATA
- || outlen[i] >= (SQLINTEGER) collen[i])
- build_indicator_message(errmsg,
- (SQLPOINTER *)data[i], collen[i],
- &outlen[i], i);
- (void)printf(" %*.*s |", (int)collen[i], (int)collen[i],
- (char *)data[i]);
- } /* for all columns in this row */
- /* print any truncation messages */
- (void)printf("\n%s", (char *)errmsg);
- }
- no_of_rows_fetched++;
- } /* while rows to fetch */
- /* Print vertical divider */
- printf("|");
- for (int i=0; i<nresultcols; i++) {
- SQLDescribeCol(hstmt, i+1, colname, sizeof(colname),
- &colnamelen, &coltype, &collen[i], &scale, &nullable);
- collen[i] = display_length(coltype, collen[i], colname);
- for (SQLUINTEGER j=0; j<collen[i]; j++) printf("-");
- printf("--+");
- }
- printf("\n");
- ndbout << no_of_rows_fetched << " rows fetched" << endl;
- }
- SQLCloseCursor(hstmt);
- break;
- /* searched DELETE, INSERT or searched UPDATE statement */
- case SQL_DIAG_DELETE_WHERE:
- case SQL_DIAG_INSERT:
- case SQL_DIAG_UPDATE_WHERE:
- /* check rowcount */
- SQLRowCount(hstmt, (SQLINTEGER*)&rowcount);
- ndbout << (int)rowcount << " rows affected" << endl;
- break;
- /* other statements */
- case SQL_DIAG_ALTER_TABLE:
- case SQL_DIAG_CREATE_TABLE:
- case SQL_DIAG_CREATE_VIEW:
- case SQL_DIAG_DROP_TABLE:
- case SQL_DIAG_DROP_VIEW:
- case SQL_DIAG_CREATE_INDEX:
- case SQL_DIAG_DROP_INDEX:
- case SQL_DIAG_DYNAMIC_DELETE_CURSOR:
- case SQL_DIAG_DYNAMIC_UPDATE_CURSOR:
- case SQL_DIAG_GRANT:
- case SQL_DIAG_REVOKE:
- ndbout << "Operation successful" << endl;
- break;
- /* implementation-defined statement */
- default:
- (void)printf("Unknown Statement type=%ld\n", stmttype);
- break;
- }
-
- /* free data buffers */
- for (int i=0; i<nresultcols; i++) {
- (void)free(data[i]);
- }
-
- SQLFreeHandle(SQL_HANDLE_STMT, hstmt); // free statement handle
- return(0);
-}
-
-/**************************************************************************
- * ------------------------------------------------------------------------
- * MODULE: Help
- * ------------------------------------------------------------------------
- **************************************************************************/
-
-void print_help() {
- ndbout << "Commands:" << endl
- << "set Print currect settings" << endl
- << "set trace N Set NDB ODBC trace level to N (0-5)" << endl
- << "set autocommit on Commit each statement (default)" << endl
- << "set autocommit off Use explicit commit/rollback - may time out!" << endl
- << "commit Commit changes to database" << endl
- << "rollback Rollback (undo) any changes" << endl
- << "whenever sqlerror Define action: exit or continue (default)" << endl
- << endl
- << "help Print this help" << endl
- << "help create Print create table examples" << endl
- << "help insert Print insert examples" << endl
- << "help select Print select examples" << endl
- << "help delete Print delete examples" << endl
- << "help update Print update examples" << endl
- << "help virtual Print help on NDB ODBC virtual tables" << endl
- << "list tables Lists all table names" << endl
- << endl
- << "All other commands are sent to the NDB ODBC SQL executor"
- << endl << endl;
-}
-
-void print_help_create() {
- ndbout << "Create Table Examples" << endl << endl
- << "create table t ( a integer not null, b char(20) not null," << endl
- << " c float, primary key(a, b) )" << endl
- << "create table t ( ndb$tid bigint unsigned primary key," << endl
- << " b char(20) not null, c float )" << endl
- << "create table t ( a int auto_increment primary key," << endl
- << " b char(20) not null, c float )" << endl
- << "create table t ( a int primary key," << endl
- << " b int default 100 )" << endl
- << endl
- << "For more information read NDB Cluster ODBC Manual."
- << endl;
-}
-
-void print_help_insert() {
- ndbout << "Insert Examples" << endl << endl
- << "insert into t(a, c) values (123, 'abc')" << endl
- << "insert into t1(a, c) select a + 10 * b, c from t2" << endl
- << "insert into t values(null, 'abc', 1.23)" << endl
- << "insert into t(b, c) values('abc', 1.23)" << endl
- << endl
- << "For more information read NDB Cluster ODBC Manual."
- << endl;
-}
-
-void print_help_select() {
- ndbout << "Select Examples" << endl << endl
- << "select a + b * c from t where a <= b + c and (b > c or c > 10)"
- << endl
- << "select a.x, b.y, c.z from t1 a, t2 b, t2 c where a.x + b.y < c.z"
- << endl
- << "select * from t1, t2 where a1 > 5 order by b1 + b2, c1 desc"
- << endl
- << "select count(*), max(a), 1 + sum(b) + avg(c * d) from t" << endl
- << "select * from t where a < 10 or b > 10" << endl
- << "select * from t where pk = 5 and b > 10" << endl
- << "select * from t1, t2, t3 where t1.pk = t2.x and t2.pk = t3.y"
- << endl << endl
- << "For more information read NDB Cluster ODBC Manual."
- << endl;
-}
-
-void print_help_update() {
- ndbout << "Update and Delete Examples" << endl << endl
- << "update t set a = b + 5, c = d where c > 10" << endl
- << "update t set a = b + 5, c = d where pk = 5 and c > 10" << endl
- << "update t set a = 5, c = 7 where pk = 5" << endl
- << "delete from t where c > 10" << endl
- << "delete from t where pk = 5 and c > 10" << endl
- << "delete from t where pk = 5" << endl
- << endl
- << "For more information read NDB Cluster ODBC Manual."
- << endl;
-}
-
-void print_help_virtual() {
- ndbout << "Virtual tables" << endl << endl
- << "* DUAL"
- << " a 1-row table - example: select SYSDATE from DUAL" << endl
- << "* ODBC$TYPEINFO" << endl
- << " corresponds to SQLGetTypeInfo" << endl
- << "* ODBC$TABLES" << endl
- << " corresponds to SQLTables (ordered by NDB table id)" << endl
- << "* ODBC$COLUMNS" << endl
- << " corresponds to SQLColumns (ordered by NDB table id)" << endl
- << "* ODBC$PRIMARYKEYS" << endl
- << " corresponds to SQLPrimaryKeys (ordered by NDB table id)" << endl
- << endl
- << "For more information read NDB Cluster ODBC Manual."
- << endl;
-}
-
-/**************************************************************************
- * ------------------------------------------------------------------------
- * MODULE: Main
- * ------------------------------------------------------------------------
- **************************************************************************/
-
-int main(int argc, const char** argv)
-{
- ndb_init();
- const char* usage = "Usage: ndbsql [-h] [-d dsn] [-f file] [stmt]\n-h help\n-d <database name or connect string>\n-f <file name> batch mode\nstmt single SQL statement\n";
- const char* dsn = "TEST_DB";
- bool helpFlg = false, batchMode = false;
- const char* fileName = 0;
- FILE* inputFile = stdin;
- const char* singleStmt = 0;
-
- s_readBuf = (char*)malloc(s_bufSize);
- while (++argv, --argc > 0) {
- const char* arg = argv[0];
- if (arg[0] != '-')
- break;
- if (strcmp(arg, "-d") == 0) {
- if (++argv, --argc > 0) {
- dsn = argv[0];
- continue;
- }
- }
- if (strcmp(arg, "-h") == 0) {
- helpFlg = true;
- continue;
- }
- if (strcmp(arg, "-f") == 0) {
- if (++argv, --argc > 0) {
- fileName = argv[0];
- continue;
- }
- }
- ndbout << usage;
- return 1;
- }
- if (helpFlg) {
- ndbout << usage << "\n";
- print_help();
- return 0;
- }
- if (fileName != 0) {
- if (argc > 0) {
- ndbout << usage;
- return 1;
- }
- if ((inputFile = fopen(fileName, "r")) == 0) {
- ndbout << "Could not read file " << fileName << ": " << strerror(errno) << endl;
- return 1;
- }
- batchMode = true;
- }
- if (argc > 0) {
- singleStmt = argv[0];
- batchMode = true;
- }
- if (! batchMode)
- ndbout << "NDB Cluster NDB SQL -- A simple SQL Command-line Interface\n\n";
-
- Con con(dsn);
- if (do_connect(con) < 0)
- return 1;
- if (! batchMode)
- ndbout << "Terminate SQL statements with a semi-colon ';'\n";
-
- char* line = 0;
- char* line2 = 0;
- char* line3 = 0;
- unsigned lineno = 0;
- bool has_semi;
- bool exit_on_error = false;
- int exit_code = 0;
- while (1) {
- free(line);
- line = 0;
- lineno = 0;
-
-more_lines:
- free(line2);
- free(line3);
- line2 = line3 = 0;
- lineno++;
- has_semi = false;
- char prompt[20];
- if (lineno == 1)
- strcpy(prompt, "SQL> ");
- else
- sprintf(prompt, "%4d ", lineno);
- if (singleStmt != 0) {
- line = strdup(singleStmt);
- int n = strlen(line);
- while (n > 0 && isspace(line[n - 1])) {
- line[--n] = 0;
- }
- if (n > 0 && line[n - 1] == ';')
- line[n - 1] = 0;
- has_semi = true; // regardless
- } else {
- const char *line1 = readline_gets(prompt, batchMode, inputFile);
- if (line1 != 0) {
- if (line == 0)
- line = strdup(line1);
- else {
- line = (char*)realloc(line, strlen(line) + 1 + strlen(line1) + 1);
- strcat(line, "\n");
- strcat(line, line1);
- }
- if (batchMode)
- ndbout << prompt << line1 << endl;
- } else {
- if (! batchMode)
- ndbout << endl;
- if (line != 0)
- ndbout << "Ignored unterminated SQL statement" << endl;
- break;
- }
- }
-
- line2 = (char*)malloc(strlen(line) + 1);
- {
- char* p = line2;
- char* q = line;
- bool str = false;
- while (*q != 0) {
- if (*q == '\'') {
- str = !str;
- *p++ = *q++;
- } else if (!str && *q == '-' && *(q + 1) == '-') {
- while (*q != 0 && *q != '\n')
- q++;
- } else
- *p++ = *q++;
- }
- *p = 0;
- int n = strlen(line2);
- while (n > 0 && isspace(line2[n - 1]))
- line2[--n] = 0;
- if (n > 0 && line2[n - 1] == ';') {
- line2[--n] = 0;
- has_semi = true;
- }
- }
- line3 = strdup(line2);
- char* tok[10];
- int ntok = 0;
- tok[ntok] = strtok(line3, " ");
- while (tok[ntok] != 0) {
- ntok++;
- if (ntok == 10)
- break;
- tok[ntok] = strtok(0, " ");
- }
- if (ntok == 0)
- continue;
-
- if (!strcasecmp(tok[0], "help") || !strcmp(tok[0], "?")) {
- if (ntok != 2)
- print_help();
- else if (!strcasecmp(tok[1], "create"))
- print_help_create();
- else if (!strcasecmp(tok[1], "insert"))
- print_help_insert();
- else if (strcasecmp(tok[1], "select"))
- print_help_select();
- else if (!strcasecmp(tok[1], "delete"))
- print_help_update();
- else if (!strcasecmp(tok[1], "update"))
- print_help_update();
- else if (!strcasecmp(tok[1], "virtual"))
- print_help_virtual();
- else
- print_help();
- continue;
- }
-
- if (!strcasecmp(tok[0], "list")) {
- if (ntok == 2 && !strcasecmp(tok[1], "tables")) {
- free(line2);
- line2 = strdup("SELECT TABLE_NAME FROM ODBC$TABLES");
- has_semi = true;
- } else {
- ndbout << "Invalid list option - try help" << endl;
- continue;
- }
- }
-
- if (ntok == 1 && !strcasecmp(tok[0], "quit"))
- break;
- if (ntok == 1 && !strcasecmp(tok[0], "exit"))
- break;
- if (ntok == 1 && !strcasecmp(tok[0], "bye"))
- break;
-
- if (!strcasecmp(tok[0], "set")) {
- if (ntok == 1) {
- char* p;
- p = getenv("NDB_ODBC_TRACE");
- ndbout << "Trace level is " << (p ? atoi(p) : 0) << endl;
- int ret = get_autocommit(con);
- if (ret != -1)
- ndbout << "Autocommit is " << (ret == SQL_AUTOCOMMIT_ON ? "on" : "off") << endl;
- } else if (ntok == 3 && !strcasecmp(tok[1], "trace")) {
- static char env[40];
- int n = tok[2] ? atoi(tok[2]) : 0;
- sprintf(env, "NDB_ODBC_TRACE=%d", n);
- putenv(env);
- ndbout << "Trace level set to " << n << endl;
- } else if (ntok == 3 && !strcasecmp(tok[1], "autocommit")) {
- if (tok[2] && !strcasecmp(tok[2], "on")) {
- int ret = set_autocommit(con, SQL_AUTOCOMMIT_ON);
- if (ret != -1)
- ndbout << "Autocommit set to ON" << endl;
- } else if (tok[2] && !strcasecmp(tok[2], "off")) {
- int ret = set_autocommit(con, SQL_AUTOCOMMIT_OFF);
- if (ret != -1)
- ndbout << "Autocommit set to OFF - transaction may time out" << endl;
- } else {
- ndbout << "Invalid autocommit option - try help" << endl;
- }
- } else {
- ndbout << "Invalid set command - try help" << endl;
- }
- continue;
- }
-
- if (ntok >= 2 &&
- !strcasecmp(tok[0], "whenever") && !strcasecmp(tok[1], "sqlerror")) {
- if (ntok == 3 && !strcasecmp(tok[2], "exit"))
- exit_on_error = true;
- else if (ntok == 3 && !strcasecmp(tok[2], "continue"))
- exit_on_error = false;
- else {
- ndbout << "Invalid whenever clause - try help" << endl;
- }
- continue;
- }
-
- if (!strcasecmp(tok[0], "commit")) {
- if (ntok == 1) {
- if (do_commit(con) != -1)
- ndbout << "Commit done" << endl;
- else {
- exit_code = 1;
- if (exit_on_error) {
- ndbout << "Exit on error" << endl;
- break;
- }
- }
- } else {
- ndbout << "Invalid commit command - try help" << endl;
- }
- continue;
- }
-
- if (!strcasecmp(tok[0], "rollback")) {
- if (ntok == 1) {
- if (do_rollback(con) != -1)
- ndbout << "Rollback done" << endl;
- else {
- exit_code = 1;
- if (exit_on_error) {
- ndbout << "Exit on error" << endl;
- break;
- }
- }
- } else {
- ndbout << "Invalid commit command - try help" << endl;
- }
- continue;
- }
-
- if (! has_semi)
- goto more_lines;
- if (do_stmt(con, line2) != 0) {
- exit_code = 1;
- if (exit_on_error) {
- ndbout << "Exit on error" << endl;
- break;
- }
- }
- if (singleStmt)
- break;
- }
- do_disconnect(con);
- return exit_code;
-}
-
-// vim: set sw=2 et:
=== removed file 'storage/ndb/tools/rgrep'
--- a/storage/ndb/tools/rgrep 2005-04-27 01:19:54 +0000
+++ b/storage/ndb/tools/rgrep 1970-01-01 00:00:00 +0000
@@ -1,194 +0,0 @@
-#!/vobs/wds/swt/bin/perl
-
-die "Usage: rgrep [-iredblLn] regexp filepat ...\n rgrep -h for help\n"
- if $#ARGV < $[;
-
-# Written by Piet van Oostrum <piet@stripped>
-# This is really free software
-
-# Mats Lidell added support for gzip.
-# Mats Lidell added support for skipping line numbers.
-
-$nextopt = 1;
-$igncase = '';
-$regpat = 0;
-$links = 0;
-$error = 0;
-$skipbin = 1;
-$havenl = 1;
-$debug = 0;
-
-do { $regexp = shift (@ARGV); } while &checkopt ($regexp);
-$icreg = $igncase;
-$igncase = '';
-
-eval 'sub grep_file {
- while (<F>) {
- $ln++;
- if (/$regexp/o' . $icreg .') {
- print "$file:$ln:" if $havenl;
- print "$_";
- print "\n" if substr($_, -1, 1) ne "\n";
- }
- }
-}';
-
-for (@ARGV) {
- if (! &checkopt ($_)) {
- if ($igncase || $regpat || /[?*[]/ || ! -e) {
- if ($regpat) {
- s/#/\\#/g;
- $_ = "#$_#";
- } else { # translate File pattern into regexp
- $re = '#($|/)'; $save = $_;
- while (/[[*?+()|.^$#]/) {
- $re .= $`;
- $c = $&;
- $_ = $';
- if ($c eq '*') { $c = '[^/]*'; }
- elsif ($c eq '?') { $c = '[^/]'; }
- elsif ($c eq '[') {
- if (/.\]/) { $c = "[$`$&"; $_ = $'; }
- else {
- $error++;
- printf stderr "Illegal filepattern %s\n", $save;
- }
- } else { $c = "\\$c"; }
- $re .= $c;
- }
- $_ = "$re$_\$#$igncase";
- }
- print "filepat: $_\n" if $debug;
- push (@filepat, $_);
- }
- else { push (@files, $_); print "file: $_\n" if $debug; }
- }
-}
-
-exit 1 if $errors ;
-
-if ($#filepat < $[) {
- eval "sub in_pat {1;}" ;
-}
-else {
- $subtxt = 'sub in_pat { local ($f) = @_;';
- $or = "";
- for (@filepat) {
- $subtxt .= $or . '$f =~ m' . $_;
- $or = " || ";
- }
- $subtxt .= ';};1';
-
- if (! eval $subtxt) {
- print $@;
- exit 1;
- }
-}
-
-@files = (".") if $#files < $[;
-
-for $file (@files) {
- &do_grep ($file);
-}
-
-sub do_grep {
- local ($file) = @_;
- local (*F, $ln, $f, $g, @dirfiles);
- if (-f $file) {
- if (open (F, $file)) {
- if (-B F) { # binary file -- may be compressed/compacted/gziped
- if (($cx1 = getc(F)) eq "\377" && (getc(F) eq "\037")) {
- open (F, "uncompact < $file|");
- if ($skipbin && -B F) { close (F); return; }
- }
- elsif ($cx1 eq "\037" && (($cx2 = getc(F)) eq "\235")) {
- open (F, "uncompress < $file|");
- if ($skipbin && -B F) { close (F); return; }
- }
- elsif ($cx1 eq "\037" && $cx2 eq "\213") {
- open (F, "gzip -d < $file|");
- if ($skipbin && -B F) { close (F); return; }
- }
- elsif ($skipbin) {
- close (F); return;
- }
- }
- print "Reading $file\n" if $debug;
- &grep_file;
- } else {
- print stderr "Cannot open $file\n";
- }
- }
- elsif (-d $file) {
- print "Entering $file\n" if $debug;
- if (opendir (F, $file)) {
- @dirfiles = readdir (F);
- closedir (F);
- for $f (@dirfiles) {
- next if ($f eq '.' || $f eq '..');
- $g = "$file/$f";
- next if (-l $g && ($links < 1 || $links == 1 && -d $g));
- if (-f $g && &in_pat ($g) || -d _) {
- &do_grep ($g);
- }
- }
- } else {
- print stderr "Can't open $file\n";
- }
- }
-}
-
-sub checkopt {
- local ($_) = $_[0];
- if (/^-/ && $nextopt) {
- $nextopt = 1;
- @opt = split (/-*/,$_); shift (@opt);
- for $opt (@opt) {
- if ($opt eq 'i') { $igncase = 'i'; }
- elsif ($opt eq 'd') { $debug = 1; }
- elsif ($opt eq 'l') { $links = 1; }
- elsif ($opt eq 'L') { $links = 2; }
- elsif ($opt eq 'b') { $skipbin = 0; }
- elsif ($opt eq 'r') { $regpat = 1; }
- elsif ($opt eq 'e') { $nextopt = 0; }
- elsif ($opt eq 'n') { $havenl = 0; }
- elsif ($opt eq 'h' || $opt eq 'H') { & help; }
- else { $error++; printf stderr "Unknown option -%s\n", $opt; }
- }
- return 1;
- }
- $nextopt = 1;
- return 0;
-}
-
-sub help {
- print <<'HELP'; exit 0;
-Usage: rgrep [-iredblL] regexp filepat ...
- regexp = perl regular expression to search
- filepat ... = a list of files and directories to be searched or
- file patterns to match filenames.
- filepat will be interpreted as file or directory name if it exists
- as such, and does not contain the metacharacters [ ] ? or *. After
- the options -i and -r all filepats will be considered patterns.
- rgrep will search all files in any of the directories given (and its
- subdirectories) that match any of the filepats, except binary files.
- Compressed files will be searched in uncompressed form.
- Note: filepats may contain / contrary to find usage.
- -b Don't skip binary files.
- -i Ignore case, either in the regexp or in filename matching (depending
- on the location). Before the regexp only applies to the regexp,
- otherwise to the filepats following it.
- -r The following filepats are treated as real perl regexps rather than
- shell style filename patterns. In this case / is not a special
- character, i.e. it is matched by . and matching is not anchored (you
- must supply ^ and $ yourself). E.g. a.b matches the file /xa/by/zz.
- -l Do follow symbolic links only for files (default is do not follow).
- -L Do follow symbolic links for files and directories.
- -e Do not interpret following argument as option. Useful if regexp or
- filepat starts with a -.
- -d Debugging: Give a lot of output on what happens.
- -n Don't precede each line by its relative line number in the file.
- -h print this message and exit.
-Piet van Oostrum <piet@stripped>
-HELP
-}
No bundle (reason: revision is a merge).
| Thread |
|---|
| • bzr commit into mysql-5.1-telco-7.0-spj-scan-vs-scan branch(ole.john.aske:3365) | Ole John Aske | 15 Nov |