← Back to team overview

maria-developers team mailing list archive

Extendet FederatedX storage engine to support updating Sphinx RT indexes

 

Hello,

the Sphinx Search engine has RT indexes, which could be updated with a subset of SQL commands, refered to as SphinxQL:

http://sphinxsearch.com/docs/2.1.1/sphinxql-reference.html

Because the FederatedX storage engine uses some commands, which Sphinx does not know, here is a patch, wich extends the FederatedX storage engine to support this subset of commands. Now its possible to update Sphinx RT indexes directly from MariaDB. To create a connection to the RT index in the Sphinx default RT-index:

index rt
{
  type = rt

  path = @CONFDIR@/data/rt

  rt_field = title
  rt_field = content

  rt_attr_string = title
  rt_attr_string = content

  rt_attr_uint = gid
}

you just have to call:

CREATE TABLE `rt` (
  `id` BIGINT UNSIGNED NOT NULL,
  `title` TEXT,
  `content` TEXT,
  `gid` INT UNSIGNED
) ENGINE=FEDERATED CONNECTION='sphinxql://root@localhost:9306/rt';

It would be great, if the attached patch could be integrated into MariaDB. If you have any suggestions, please feel free to contact me.

Best regards,


Markus Lidel
diff -urN storage/federatedx.ori/CMakeLists.txt storage/federatedx/CMakeLists.txt
--- storage/federatedx.ori/CMakeLists.txt	2013-04-23 06:14:00.000000000 +0200
+++ storage/federatedx/CMakeLists.txt	2013-05-28 11:49:44.000000000 +0200
@@ -1,4 +1,4 @@
 SET(FEDERATEDX_PLUGIN_STATIC  "federatedx")
 SET(FEDERATEDX_PLUGIN_DYNAMIC "ha_federatedx")
-SET(FEDERATEDX_SOURCES  ha_federatedx.cc federatedx_txn.cc federatedx_io.cc federatedx_io_null.cc federatedx_io_mysql.cc)
+SET(FEDERATEDX_SOURCES  ha_federatedx.cc federatedx_txn.cc federatedx_io.cc federatedx_io_null.cc federatedx_io_mysql.cc federatedx_io_sphinxql.cc)
 MYSQL_ADD_PLUGIN(federatedx ${FEDERATEDX_SOURCES} STORAGE_ENGINE)
diff -urN storage/federatedx.ori/federatedx_io.cc storage/federatedx/federatedx_io.cc
--- storage/federatedx.ori/federatedx_io.cc	2013-04-23 06:14:00.000000000 +0200
+++ storage/federatedx/federatedx_io.cc	2013-05-28 16:04:48.000000000 +0200
@@ -27,13 +27,20 @@
 */
 
 
-/*#define MYSQL_SERVER 1*/
+#define MYSQL_SERVER 1
 #include "sql_priv.h"
 #include <mysql/plugin.h>
 
 #include "ha_federatedx.h"
 
 #include "m_string.h"
+#include "sql_servers.h"
+#include "sql_analyse.h"                        // append_escaped()
+
+#include "federatedx_io.h"
+#include "federatedx_io_null.h"
+#include "federatedx_io_mysql.h"
+#include "federatedx_io_sphinxql.h"
 
 #ifdef USE_PRAGMA_IMPLEMENTATION
 #pragma implementation                          // gcc: Class implementation
@@ -50,12 +57,19 @@
 
 static const io_schemes_st federated_io_schemes[] =
 {
-  { "mysql", &instantiate_io_mysql },
-  { "null", instantiate_io_null } /* must be last element */
+  { "mysql", &federatedx_io_mysql::construct },
+  { "sphinxql", &federatedx_io_sphinxql::construct },
+  { "null", &federatedx_io_null::construct } /* must be last element */
 };
 
 const uint federated_io_schemes_count= array_elements(federated_io_schemes);
 
+/* Variables used when chopping off trailing characters */
+static const uint sizeof_trailing_comma= sizeof(", ") - 1;
+static const uint sizeof_trailing_closeparen= sizeof(") ") - 1;
+static const uint sizeof_trailing_and= sizeof(" AND ") - 1;
+static const uint sizeof_trailing_where= sizeof(" WHERE ") - 1;
+
 federatedx_io::federatedx_io(FEDERATEDX_SERVER *aserver)
   : server(aserver), owner_ptr(0), txn_next(0), idle_next(0),
     active(FALSE), busy(FALSE), readonly(TRUE)
@@ -69,7 +83,6 @@
   DBUG_VOID_RETURN;
 }
 
-
 federatedx_io::~federatedx_io()
 {
   DBUG_ENTER("federatedx_io::~federatedx_io");
@@ -79,7 +92,6 @@
   DBUG_VOID_RETURN;
 }
 
-
 bool federatedx_io::handles_scheme(const char *scheme)
 {
   const io_schemes_st *ptr = federated_io_schemes;
@@ -89,7 +101,6 @@
   return ptr != end;
 }
 
-
 federatedx_io *federatedx_io::construct(MEM_ROOT *server_root,
                                         FEDERATEDX_SERVER *server)
 {
@@ -100,4 +111,131 @@
   return ptr->instantiate(server_root, server);
 }
 
+void federatedx_io::reset()
+{
+}
+
+int federatedx_io::commit()
+{
+  return 0;
+}
+
+int federatedx_io::rollback()
+{
+  return 0;
+}
+
+ulong federatedx_io::last_savepoint() const
+{
+  return 0;
+}
+
+ulong federatedx_io::actual_savepoint() const
+{
+  return 0;
+}
+
+bool federatedx_io::is_autocommit() const
+{
+  return TRUE;
+}
+
+int federatedx_io::savepoint_set(ulong sp)
+{
+  return 0;
+}
 
+ulong federatedx_io::savepoint_release(ulong sp)
+{
+  return 0;
+}
+
+ulong federatedx_io::savepoint_rollback(ulong sp)
+{
+  return 0;
+}
+
+void federatedx_io::savepoint_restrict(ulong sp)
+{
+}
+
+size_t federatedx_io::max_query_size() const
+{
+  return INT_MAX;
+}
+
+int federatedx_io::test_connection(MYSQL_THD thd, FEDERATEDX_SHARE *share)
+{
+  return 0;
+}
+
+int federatedx_io::delete_row(FEDERATEDX_SHARE *share, TABLE *table, const uchar *buf)
+{
+  char delete_buffer[FEDERATEDX_QUERY_BUFFER_SIZE];
+  char data_buffer[FEDERATEDX_QUERY_BUFFER_SIZE];
+  String delete_string(delete_buffer, sizeof(delete_buffer), &my_charset_bin);
+  String data_string(data_buffer, sizeof(data_buffer), &my_charset_bin);
+  uint found= 0;
+  DBUG_ENTER("federatedx_io::delete_row");
+
+  delete_string.length(0);
+  delete_string.append(STRING_WITH_LEN("DELETE FROM "));
+  append_ident(&delete_string, share->table_name,
+               share->table_name_length, ident_quote_char);
+  delete_string.append(STRING_WITH_LEN(" WHERE "));
+
+  for (Field **field= table->field; *field; field++)
+  {
+    Field *cur_field= *field;
+    found++;
+    if (bitmap_is_set(table->read_set, cur_field->field_index))
+    {
+      append_ident(&delete_string, (*field)->field_name,
+                   strlen((*field)->field_name), ident_quote_char);
+      data_string.length(0);
+      if (cur_field->is_null())
+      {
+        delete_string.append(STRING_WITH_LEN(" IS NULL "));
+      }
+      else
+      {
+        bool needs_quote= cur_field->str_needs_quotes();
+        delete_string.append(STRING_WITH_LEN(" = "));
+        cur_field->val_str(&data_string);
+        if (needs_quote)
+          delete_string.append(value_quote_char);
+        data_string.print(&delete_string);
+        if (needs_quote)
+          delete_string.append(value_quote_char);
+      }
+      delete_string.append(STRING_WITH_LEN(" AND "));
+    }
+  }
+
+  // Remove trailing AND
+  delete_string.length(delete_string.length() - sizeof_trailing_and);
+  if (!found)
+    delete_string.length(delete_string.length() - sizeof_trailing_where);
+
+  delete_string.append(STRING_WITH_LEN(" LIMIT 1"));
+  DBUG_PRINT("info",
+             ("Delete sql: %s", delete_string.c_ptr_quick()));
+
+  DBUG_RETURN(this->query(delete_string.ptr(), delete_string.length()));
+}
+
+int federatedx_io::delete_all_rows(FEDERATEDX_SHARE *share, TABLE *table)
+{
+  char query_buffer[FEDERATEDX_QUERY_BUFFER_SIZE];
+  String query(query_buffer, sizeof(query_buffer), &my_charset_bin);
+  DBUG_ENTER("ha_federatedx::delete_all_rows");
+
+  query.length(0);
+
+  query.set_charset(system_charset_info);
+  query.append(STRING_WITH_LEN("TRUNCATE "));
+  append_ident(&query, share->table_name, share->table_name_length,
+               ident_quote_char);
+
+  DBUG_RETURN(this->query(query.ptr(), query.length()));
+}
diff -urN storage/federatedx.ori/federatedx_io.h storage/federatedx/federatedx_io.h
--- storage/federatedx.ori/federatedx_io.h	1970-01-01 01:00:00.000000000 +0100
+++ storage/federatedx/federatedx_io.h	2013-05-28 11:41:50.000000000 +0200
@@ -0,0 +1,140 @@
+/*
+Copyright (c) 2008, Patrick Galbraith
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+    * Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above
+copyright notice, this list of conditions and the following disclaimer
+in the documentation and/or other materials provided with the
+distribution.
+
+    * Neither the name of Patrick Galbraith nor the names of its
+contributors may be used to endorse or promote products derived from
+this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifdef USE_PRAGMA_INTERFACE
+#pragma interface
+#endif
+
+class federatedx_io
+{
+  friend class federatedx_txn;
+  FEDERATEDX_SERVER * const server;
+  federatedx_io **owner_ptr;
+  federatedx_io *txn_next;
+  federatedx_io *idle_next;
+  bool active;  /* currently participating in a transaction */
+  bool busy;    /* in use by a ha_federated instance */
+  bool readonly;/* indicates that no updates have occurred */
+
+protected:
+  void set_active(bool new_active)
+  { active= new_active; }
+
+public:
+  static bool handles_scheme(const char *scheme);
+  static federatedx_io *construct(MEM_ROOT *server_root,
+                                  FEDERATEDX_SERVER *server);
+
+  static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
+  { return alloc_root(mem_root, size); }
+  static void operator delete(void *ptr, size_t size)
+  { TRASH(ptr, size); }
+
+  federatedx_io(FEDERATEDX_SERVER *);
+  virtual ~federatedx_io();
+
+  bool is_readonly() const { return readonly; }
+  bool is_active() const { return active; }
+
+  const char * get_charsetname() const
+  { return server->csname ? server->csname : "latin1"; }
+
+  const char * get_hostname() const { return server->hostname; }
+  const char * get_username() const { return server->username; }
+  const char * get_password() const { return server->password; }
+  const char * get_database() const { return server->database; }
+  ushort       get_port() const     { return server->port; }
+  const char * get_socket() const   { return server->socket; }
+
+  /* query and metadata functions */
+
+  virtual int query(const char *buffer, uint length)=0;
+
+  virtual my_ulonglong affected_rows() const=0;
+  virtual my_ulonglong last_insert_id() const=0;
+
+  virtual size_t max_query_size() const;
+
+  virtual bool table_metadata(ha_statistics *stats, const char *table_name,
+                              uint table_name_length, uint flag) = 0;
+
+  /* error handling functions */
+
+  virtual int error_code()=0;
+  virtual const char *error_str()=0;
+
+  /* transactional functions */
+
+  virtual bool is_autocommit() const;
+
+  virtual void reset();
+  virtual int commit();
+  virtual int rollback();
+
+  virtual int savepoint_set(ulong sp);
+  virtual ulong savepoint_release(ulong sp);
+  virtual ulong savepoint_rollback(ulong sp);
+  virtual void savepoint_restrict(ulong sp);
+
+  virtual ulong last_savepoint() const;
+  virtual ulong actual_savepoint() const;
+
+  /* resultset operations */
+
+  virtual FEDERATEDX_IO_RESULT *store_result()=0;
+  virtual void free_result(FEDERATEDX_IO_RESULT *io_result)=0;
+
+  virtual unsigned int get_num_fields(FEDERATEDX_IO_RESULT *io_result)=0;
+  virtual my_ulonglong get_num_rows(FEDERATEDX_IO_RESULT *io_result)=0;
+
+  virtual FEDERATEDX_IO_ROW *fetch_row(FEDERATEDX_IO_RESULT *io_result)=0;
+  virtual ulong *fetch_lengths(FEDERATEDX_IO_RESULT *io_result)=0;
+
+  virtual const char *get_column_data(FEDERATEDX_IO_ROW *row,
+                                      unsigned int column)=0;
+  virtual bool is_column_null(const FEDERATEDX_IO_ROW *row,
+                              unsigned int column) const=0;
+
+  virtual size_t get_ref_length() const=0;
+
+  virtual void mark_position(FEDERATEDX_IO_RESULT *io_result,
+                             void *ref)=0;
+  virtual int seek_position(FEDERATEDX_IO_RESULT **io_result,
+                            const void *ref)=0;
+
+  /* extended functions */
+  virtual int test_connection(MYSQL_THD thd, FEDERATEDX_SHARE *share);
+
+  virtual int delete_row(FEDERATEDX_SHARE *share, TABLE *table, const uchar *buf);
+  virtual int delete_all_rows(FEDERATEDX_SHARE *share, TABLE *table);
+};
diff -urN storage/federatedx.ori/federatedx_io_mysql.cc storage/federatedx/federatedx_io_mysql.cc
--- storage/federatedx.ori/federatedx_io_mysql.cc	2013-04-23 06:13:56.000000000 +0200
+++ storage/federatedx/federatedx_io_mysql.cc	2013-05-28 11:39:10.000000000 +0200
@@ -35,6 +35,10 @@
 
 #include "m_string.h"
 #include "sql_servers.h"
+#include "sql_show.h"                           // append_identifier()
+
+#include "federatedx_io.h"
+#include "federatedx_io_mysql.h"
 
 #ifdef USE_PRAGMA_IMPLEMENTATION
 #pragma implementation                          // gcc: Class implementation
@@ -59,69 +63,8 @@
 };
 
 
-class federatedx_io_mysql :public federatedx_io
-{
-  MYSQL mysql; /* MySQL connection */
-  DYNAMIC_ARRAY savepoints;
-  bool requested_autocommit;
-  bool actual_autocommit;
-
-  int actual_query(const char *buffer, uint length);
-  bool test_all_restrict() const;
-public:
-  federatedx_io_mysql(FEDERATEDX_SERVER *);
-  ~federatedx_io_mysql();
-
-  int simple_query(const char *fmt, ...);
-  int query(const char *buffer, uint length);
-  virtual FEDERATEDX_IO_RESULT *store_result();
-
-  virtual size_t max_query_size() const;
-
-  virtual my_ulonglong affected_rows() const;
-  virtual my_ulonglong last_insert_id() const;
-
-  virtual int error_code();
-  virtual const char *error_str();
-
-  void reset();
-  int commit();
-  int rollback();
-
-  int savepoint_set(ulong sp);
-  ulong savepoint_release(ulong sp);
-  ulong savepoint_rollback(ulong sp);
-  void savepoint_restrict(ulong sp);
-
-  ulong last_savepoint() const;
-  ulong actual_savepoint() const;
-  bool is_autocommit() const;
-
-  bool table_metadata(ha_statistics *stats, const char *table_name,
-                      uint table_name_length, uint flag);
-
-  /* resultset operations */
-
-  virtual void free_result(FEDERATEDX_IO_RESULT *io_result);
-  virtual unsigned int get_num_fields(FEDERATEDX_IO_RESULT *io_result);
-  virtual my_ulonglong get_num_rows(FEDERATEDX_IO_RESULT *io_result);
-  virtual FEDERATEDX_IO_ROW *fetch_row(FEDERATEDX_IO_RESULT *io_result);
-  virtual ulong *fetch_lengths(FEDERATEDX_IO_RESULT *io_result);
-  virtual const char *get_column_data(FEDERATEDX_IO_ROW *row,
-                                      unsigned int column);
-  virtual bool is_column_null(const FEDERATEDX_IO_ROW *row,
-                              unsigned int column) const;
-
-  virtual size_t get_ref_length() const;
-  virtual void mark_position(FEDERATEDX_IO_RESULT *io_result,
-                             void *ref);
-  virtual int seek_position(FEDERATEDX_IO_RESULT **io_result,
-                            const void *ref);
-};
-
-
-federatedx_io *instantiate_io_mysql(MEM_ROOT *server_root,
-                                    FEDERATEDX_SERVER *server)
+federatedx_io *federatedx_io_mysql::construct(MEM_ROOT *server_root,
+                                              FEDERATEDX_SERVER *server)
 {
   return new (server_root) federatedx_io_mysql(server);
 }
@@ -648,3 +591,30 @@
   return 0;
 }
 
+int federatedx_io_mysql::test_connection(MYSQL_THD thd, FEDERATEDX_SHARE *share)
+{
+  char buffer[FEDERATEDX_QUERY_BUFFER_SIZE];
+  String str(buffer, sizeof(buffer), &my_charset_bin);
+  FEDERATEDX_IO_RESULT *resultset= NULL;
+  int retval;
+
+  str.length(0);
+  str.append(STRING_WITH_LEN("SELECT * FROM "));
+  append_identifier(thd, &str, share->table_name,
+                    share->table_name_length);
+  str.append(STRING_WITH_LEN(" WHERE 1=0"));
+
+  if ((retval= this->query(str.ptr(), str.length())))
+  {
+    sprintf(buffer, "database: '%s'  username: '%s'  hostname: '%s'",
+            share->database, share->username, share->hostname);
+    DBUG_PRINT("info", ("error-code: %d", this->error_code()));
+    my_error(ER_CANT_CREATE_FEDERATED_TABLE, MYF(0), buffer);
+  }
+  else
+    resultset= this->store_result();
+
+  this->free_result(resultset);
+
+  return retval;
+}
diff -urN storage/federatedx.ori/federatedx_io_mysql.h storage/federatedx/federatedx_io_mysql.h
--- storage/federatedx.ori/federatedx_io_mysql.h	1970-01-01 01:00:00.000000000 +0100
+++ storage/federatedx/federatedx_io_mysql.h	2013-05-28 12:34:48.000000000 +0200
@@ -0,0 +1,99 @@
+/*
+Copyright (c) 2007, Antony T Curtis
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+    * Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+    * Neither the name of FederatedX nor the names of its
+contributors may be used to endorse or promote products derived from
+this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifdef USE_PRAGMA_INTERFACE
+#pragma interface
+#endif
+
+class federatedx_io_mysql :public federatedx_io
+{
+protected:
+  MYSQL mysql; /* MySQL connection */
+  DYNAMIC_ARRAY savepoints;
+  bool requested_autocommit;
+  bool actual_autocommit;
+
+  bool test_all_restrict() const;
+
+  int actual_query(const char *buffer, uint length);
+
+public:
+  static federatedx_io *construct(MEM_ROOT *server_root,
+                                  FEDERATEDX_SERVER *server);
+
+  federatedx_io_mysql(FEDERATEDX_SERVER *);
+  ~federatedx_io_mysql();
+
+  int simple_query(const char *fmt, ...);
+  virtual int query(const char *buffer, uint length);
+  FEDERATEDX_IO_RESULT *store_result();
+
+  size_t max_query_size() const;
+
+  my_ulonglong affected_rows() const;
+  my_ulonglong last_insert_id() const;
+
+  int error_code();
+  const char *error_str();
+
+  void reset();
+  int commit();
+  int rollback();
+
+  int savepoint_set(ulong sp);
+  ulong savepoint_release(ulong sp);
+  ulong savepoint_rollback(ulong sp);
+  void savepoint_restrict(ulong sp);
+
+  ulong last_savepoint() const;
+  ulong actual_savepoint() const;
+  bool is_autocommit() const;
+
+  bool table_metadata(ha_statistics *stats, const char *table_name,
+                      uint table_name_length, uint flag);
+
+  int test_connection(MYSQL_THD thd, FEDERATEDX_SHARE *share);
+
+  /* resultset operations */
+
+  void free_result(FEDERATEDX_IO_RESULT *io_result);
+  unsigned int get_num_fields(FEDERATEDX_IO_RESULT *io_result);
+  my_ulonglong get_num_rows(FEDERATEDX_IO_RESULT *io_result);
+  FEDERATEDX_IO_ROW *fetch_row(FEDERATEDX_IO_RESULT *io_result);
+  ulong *fetch_lengths(FEDERATEDX_IO_RESULT *io_result);
+  const char *get_column_data(FEDERATEDX_IO_ROW *row,
+                              unsigned int column);
+  bool is_column_null(const FEDERATEDX_IO_ROW *row,
+                      unsigned int column) const;
+
+  size_t get_ref_length() const;
+  void mark_position(FEDERATEDX_IO_RESULT *io_result,
+                     void *ref);
+  int seek_position(FEDERATEDX_IO_RESULT **io_result,
+                    const void *ref);
+};
diff -urN storage/federatedx.ori/federatedx_io_null.cc storage/federatedx/federatedx_io_null.cc
--- storage/federatedx.ori/federatedx_io_null.cc	2013-04-23 06:14:00.000000000 +0200
+++ storage/federatedx/federatedx_io_null.cc	2013-05-28 09:27:00.000000000 +0200
@@ -35,77 +35,16 @@
 
 #include "m_string.h"
 
+#include "federatedx_io.h"
+#include "federatedx_io_null.h"
+
 #ifdef USE_PRAGMA_IMPLEMENTATION
 #pragma implementation                          // gcc: Class implementation
 #endif
 
 
-#define SAVEPOINT_REALIZED  1
-#define SAVEPOINT_RESTRICT  2
-#define SAVEPOINT_EMITTED 4
-
-
-typedef struct federatedx_savepoint
-{
-  ulong level;
-  uint  flags;
-} SAVEPT;
-
-
-class federatedx_io_null :public federatedx_io
-{
-public:
-  federatedx_io_null(FEDERATEDX_SERVER *);
-  ~federatedx_io_null();
-
-  int query(const char *buffer, uint length);
-  virtual FEDERATEDX_IO_RESULT *store_result();
-
-  virtual size_t max_query_size() const;
-
-  virtual my_ulonglong affected_rows() const;
-  virtual my_ulonglong last_insert_id() const;
-
-  virtual int error_code();
-  virtual const char *error_str();
-  
-  void reset();
-  int commit();
-  int rollback();
-  
-  int savepoint_set(ulong sp);
-  ulong savepoint_release(ulong sp);
-  ulong savepoint_rollback(ulong sp);
-  void savepoint_restrict(ulong sp);
-  
-  ulong last_savepoint() const;
-  ulong actual_savepoint() const;
-  bool is_autocommit() const;
-
-  bool table_metadata(ha_statistics *stats, const char *table_name,
-                      uint table_name_length, uint flag);
-  
-  /* resultset operations */
-  
-  virtual void free_result(FEDERATEDX_IO_RESULT *io_result);
-  virtual unsigned int get_num_fields(FEDERATEDX_IO_RESULT *io_result);
-  virtual my_ulonglong get_num_rows(FEDERATEDX_IO_RESULT *io_result);
-  virtual FEDERATEDX_IO_ROW *fetch_row(FEDERATEDX_IO_RESULT *io_result);
-  virtual ulong *fetch_lengths(FEDERATEDX_IO_RESULT *io_result);
-  virtual const char *get_column_data(FEDERATEDX_IO_ROW *row,
-                                      unsigned int column);
-  virtual bool is_column_null(const FEDERATEDX_IO_ROW *row,
-                              unsigned int column) const;
-  virtual size_t get_ref_length() const;
-  virtual void mark_position(FEDERATEDX_IO_RESULT *io_result,
-                             void *ref);
-  virtual int seek_position(FEDERATEDX_IO_RESULT **io_result,
-                            const void *ref);
-};
-
-
-federatedx_io *instantiate_io_null(MEM_ROOT *server_root,
-                                   FEDERATEDX_SERVER *server)
+federatedx_io *federatedx_io_null::construct(MEM_ROOT *server_root,
+                                             FEDERATEDX_SERVER *server)
 {
   return new (server_root) federatedx_io_null(server);
 }
@@ -122,74 +61,12 @@
 }
 
 
-void federatedx_io_null::reset()
-{
-}
-
-
-int federatedx_io_null::commit()
-{
-  return 0;
-}
-
-int federatedx_io_null::rollback()
-{
-  return 0;
-}
-
-
-ulong federatedx_io_null::last_savepoint() const
-{
-  return 0;
-}
-
-
-ulong federatedx_io_null::actual_savepoint() const
-{
-  return 0;
-}
-
-bool federatedx_io_null::is_autocommit() const
-{
-  return 0;
-}
-
-
-int federatedx_io_null::savepoint_set(ulong sp)
-{
-  return 0;
-}
-
-
-ulong federatedx_io_null::savepoint_release(ulong sp)
-{
-  return 0;
-}
-
-
-ulong federatedx_io_null::savepoint_rollback(ulong sp)
-{
-  return 0;
-}
-
-
-void federatedx_io_null::savepoint_restrict(ulong sp)
-{
-}
-
-
 int federatedx_io_null::query(const char *buffer, uint length)
 {
   return 0;
 }
 
 
-size_t federatedx_io_null::max_query_size() const
-{
-  return INT_MAX;
-}
-
-
 my_ulonglong federatedx_io_null::affected_rows() const
 {
   return 0;
diff -urN storage/federatedx.ori/federatedx_io_null.h storage/federatedx/federatedx_io_null.h
--- storage/federatedx.ori/federatedx_io_null.h	1970-01-01 01:00:00.000000000 +0100
+++ storage/federatedx/federatedx_io_null.h	2013-05-28 09:55:08.000000000 +0200
@@ -0,0 +1,70 @@
+/*
+Copyright (c) 2007, Antony T Curtis
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+    * Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+    * Neither the name of FederatedX nor the names of its
+contributors may be used to endorse or promote products derived from
+this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifdef USE_PRAGMA_INTERFACE
+#pragma interface
+#endif
+
+class federatedx_io_null :public federatedx_io
+{
+public:
+  static federatedx_io *construct(MEM_ROOT *server_root,
+                                  FEDERATEDX_SERVER *server);
+
+  federatedx_io_null(FEDERATEDX_SERVER *);
+  ~federatedx_io_null();
+
+  int query(const char *buffer, uint length);
+  FEDERATEDX_IO_RESULT *store_result();
+
+  my_ulonglong affected_rows() const;
+  my_ulonglong last_insert_id() const;
+
+  int error_code();
+  const char *error_str();
+
+  bool table_metadata(ha_statistics *stats, const char *table_name,
+                      uint table_name_length, uint flag);
+
+  /* resultset operations */
+
+  void free_result(FEDERATEDX_IO_RESULT *io_result);
+  unsigned int get_num_fields(FEDERATEDX_IO_RESULT *io_result);
+  my_ulonglong get_num_rows(FEDERATEDX_IO_RESULT *io_result);
+  FEDERATEDX_IO_ROW *fetch_row(FEDERATEDX_IO_RESULT *io_result);
+  ulong *fetch_lengths(FEDERATEDX_IO_RESULT *io_result);
+  const char *get_column_data(FEDERATEDX_IO_ROW *row,
+                              unsigned int column);
+  bool is_column_null(const FEDERATEDX_IO_ROW *row,
+                      unsigned int column) const;
+  size_t get_ref_length() const;
+  void mark_position(FEDERATEDX_IO_RESULT *io_result,
+                     void *ref);
+  int seek_position(FEDERATEDX_IO_RESULT **io_result,
+                    const void *ref);
+};
diff -urN storage/federatedx.ori/federatedx_io_sphinxql.cc storage/federatedx/federatedx_io_sphinxql.cc
--- storage/federatedx.ori/federatedx_io_sphinxql.cc	1970-01-01 01:00:00.000000000 +0100
+++ storage/federatedx/federatedx_io_sphinxql.cc	2013-05-28 16:31:38.000000000 +0200
@@ -0,0 +1,203 @@
+/*
+Copyright (c) 2007, Antony T Curtis
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+    * Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+    * Neither the name of FederatedX nor the names of its
+contributors may be used to endorse or promote products derived from
+this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+#define MYSQL_SERVER 1
+#include "sql_priv.h"
+#include <mysql/plugin.h>
+
+#include "ha_federatedx.h"
+
+#include "m_string.h"
+#include "sql_servers.h"
+#include "sql_show.h"                           // append_identifier()
+
+#include "federatedx_io.h"
+#include "federatedx_io_mysql.h"
+#include "federatedx_io_sphinxql.h"
+
+#ifdef USE_PRAGMA_IMPLEMENTATION
+#pragma implementation                          // gcc: Class implementation
+#endif
+
+#define SPHINX_MAX_ROWS 1000000
+
+federatedx_io *federatedx_io_sphinxql::construct(MEM_ROOT *server_root,
+                                                 FEDERATEDX_SERVER *server)
+{
+  return new (server_root) federatedx_io_sphinxql(server);
+}
+
+federatedx_io_sphinxql::federatedx_io_sphinxql(FEDERATEDX_SERVER *aserver)
+  : federatedx_io_mysql(aserver)
+{
+  DBUG_ENTER("federatedx_io_sphinxql::federatedx_io_sphinxql");
+
+  DBUG_VOID_RETURN;
+}
+
+federatedx_io_sphinxql::~federatedx_io_sphinxql()
+{
+  DBUG_ENTER("federatedx_io_sphinxql::~federatedx_io_sphinxql");
+
+  DBUG_VOID_RETURN;
+}
+
+int federatedx_io_sphinxql::query(const char *buffer, uint length)
+{
+  char query_buffer[FEDERATEDX_QUERY_BUFFER_SIZE];
+  String query(query_buffer, sizeof(query_buffer), &my_charset_bin);
+  int error;
+  bool wants_autocommit= requested_autocommit | is_readonly();
+  DBUG_ENTER("federatedx_io_sphinxql::query");
+
+  if (!wants_autocommit && test_all_restrict())
+    wants_autocommit= TRUE;
+
+  if (wants_autocommit != actual_autocommit)
+  {
+    if ((error= actual_query(wants_autocommit ? "SET AUTOCOMMIT=1"
+                                            : "SET AUTOCOMMIT=0", 16)))
+    DBUG_RETURN(error);
+    mysql.reconnect= wants_autocommit ? 1 : 0;
+    actual_autocommit= wants_autocommit;
+  }
+
+  query.copy(buffer, length, &my_charset_bin);
+
+  if (!strncasecmp(query.c_ptr(), STRING_WITH_LEN("SELECT ")) &&
+      !strstr(query.c_ptr(), " LIMIT "))
+  {
+    query.append(" LIMIT ");
+    query.append_ulonglong(SPHINX_MAX_ROWS);
+  }
+
+  if (!(error= actual_query(query.ptr(), query.length())))
+    set_active(is_active() || !actual_autocommit);
+
+  DBUG_RETURN(error);
+}
+
+int federatedx_io_sphinxql::test_connection(MYSQL_THD thd, FEDERATEDX_SHARE *share)
+{
+  char buffer[FEDERATEDX_QUERY_BUFFER_SIZE];
+  String str(buffer, sizeof(buffer), &my_charset_bin);
+  FEDERATEDX_IO_RESULT *resultset= NULL;
+  int retval;
+
+  str.length(0);
+  str.append(STRING_WITH_LEN("SELECT * FROM "));
+  str.append(share->table_name, share->table_name_length);
+  str.append(STRING_WITH_LEN(" LIMIT 0"));
+
+  if ((retval= this->query(str.ptr(), str.length())))
+  {
+    sprintf(buffer, "database: '%s'  username: '%s'  hostname: '%s'",
+            share->database, share->username, share->hostname);
+    DBUG_PRINT("info", ("error-code: %d", this->error_code()));
+    my_error(ER_CANT_CREATE_FEDERATED_TABLE, MYF(0), buffer);
+  }
+  else
+    resultset= this->store_result();
+
+  this->free_result(resultset);
+
+  return retval;
+}
+
+bool federatedx_io_sphinxql::table_metadata(ha_statistics *stats,
+                                         const char *table_name,
+                                         uint table_name_length, uint flag)
+{
+  return 0;
+}
+
+int federatedx_io_sphinxql::delete_row(FEDERATEDX_SHARE *share, TABLE *table, const uchar *buf)
+{
+  char delete_buffer[FEDERATEDX_QUERY_BUFFER_SIZE];
+  char data_buffer[FEDERATEDX_QUERY_BUFFER_SIZE];
+  String delete_string(delete_buffer, sizeof(delete_buffer), &my_charset_bin);
+  String data_string(data_buffer, sizeof(data_buffer), &my_charset_bin);
+  uint found= 0;
+  DBUG_ENTER("federatedx_io_sphinxql::delete_row");
+
+  delete_string.length(0);
+  delete_string.append(STRING_WITH_LEN("DELETE FROM "));
+  append_ident(&delete_string, share->table_name,
+               share->table_name_length, ident_quote_char);
+  delete_string.append(STRING_WITH_LEN(" WHERE "));
+
+  for (Field **field= table->field; *field; field++)
+  {
+    Field *cur_field= *field;
+    found++;
+    if (bitmap_is_set(table->read_set, cur_field->field_index))
+    {
+      append_ident(&delete_string, (*field)->field_name,
+                   strlen((*field)->field_name), ident_quote_char);
+      data_string.length(0);
+      if (cur_field->is_null())
+      {
+        delete_string.append(STRING_WITH_LEN(" IS NULL "));
+      }
+      else
+      {
+        bool needs_quote= cur_field->str_needs_quotes();
+        delete_string.append(STRING_WITH_LEN(" = "));
+        cur_field->val_str(&data_string);
+        if (needs_quote)
+          delete_string.append(value_quote_char);
+        data_string.print(&delete_string);
+        if (needs_quote)
+          delete_string.append(value_quote_char);
+      }
+      break;
+    }
+  }
+
+  // Remove trailing WHERE
+  if (!found)
+    delete_string.length(delete_string.length() - sizeof(" WHERE ") - 1);
+
+  DBUG_PRINT("info",
+             ("Delete sql: %s", delete_string.c_ptr_quick()));
+
+  if (this->query(delete_string.ptr(), delete_string.length()))
+  {
+    DBUG_RETURN(1);
+  }
+
+  DBUG_RETURN(0);
+}
+
+int federatedx_io_sphinxql::delete_all_rows(FEDERATEDX_SHARE *share, TABLE *table)
+{
+  DBUG_ENTER("federatedx_io_sphinxql::delete_all_rows");
+
+  DBUG_RETURN(HA_ERR_WRONG_COMMAND);
+}
\ No newline at end of file
diff -urN storage/federatedx.ori/federatedx_io_sphinxql.h storage/federatedx/federatedx_io_sphinxql.h
--- storage/federatedx.ori/federatedx_io_sphinxql.h	1970-01-01 01:00:00.000000000 +0100
+++ storage/federatedx/federatedx_io_sphinxql.h	2013-05-28 15:58:46.000000000 +0200
@@ -0,0 +1,50 @@
+/*
+Copyright (c) 2007, Antony T Curtis
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+    * Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+    * Neither the name of FederatedX nor the names of its
+contributors may be used to endorse or promote products derived from
+this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifdef USE_PRAGMA_INTERFACE
+#pragma interface
+#endif
+
+class federatedx_io_sphinxql :public federatedx_io_mysql
+{
+public:
+  static federatedx_io *construct(MEM_ROOT *server_root,
+                                  FEDERATEDX_SERVER *server);
+
+  federatedx_io_sphinxql(FEDERATEDX_SERVER *);
+  ~federatedx_io_sphinxql();
+
+  int query(const char *buffer, uint length);
+
+  bool table_metadata(ha_statistics *stats, const char *table_name,
+                      uint table_name_length, uint flag);
+
+  int test_connection(MYSQL_THD thd, FEDERATEDX_SHARE *share);
+  int delete_row(FEDERATEDX_SHARE *share, TABLE *table, const uchar *buf);
+  int delete_all_rows(FEDERATEDX_SHARE *share, TABLE *table);
+};
diff -urN storage/federatedx.ori/federatedx_txn.cc storage/federatedx/federatedx_txn.cc
--- storage/federatedx.ori/federatedx_txn.cc	2013-04-23 06:14:00.000000000 +0200
+++ storage/federatedx/federatedx_txn.cc	2013-05-28 09:22:32.000000000 +0200
@@ -40,6 +40,8 @@
 #include "table.h"
 #include "sql_servers.h"
 
+#include "federatedx_io.h"
+
 federatedx_txn::federatedx_txn()
   : txn_list(0), savepoint_level(0), savepoint_stmt(0), savepoint_next(0)
 {
@@ -232,12 +234,11 @@
       int rc= 0;
 
       if (io->active)
-	rc= io->commit();
-      else
-	io->rollback();
-
-      if (io->active && rc)
-	error= -1;
+	  {
+	    if (rc= io->commit())
+		  error= -1;
+	  } else
+	    io->rollback();
 
       io->reset();
     }
diff -urN storage/federatedx.ori/ha_federatedx.cc storage/federatedx/ha_federatedx.cc
--- storage/federatedx.ori/ha_federatedx.cc	2013-04-23 06:13:59.000000000 +0200
+++ storage/federatedx/ha_federatedx.cc	2013-05-28 16:35:46.000000000 +0200
@@ -316,7 +316,8 @@
 #include "ha_federatedx.h"
 #include "sql_servers.h"
 #include "sql_analyse.h"                        // append_escaped()
-#include "sql_show.h"                           // append_identifier()
+
+#include "federatedx_io.h"
 
 #ifdef I_AM_PARANOID
 #define MIN_PORT 1023
@@ -616,6 +617,13 @@
     CONNECTION="scheme://username@hostname:port/database/table"
     CONNECTION="scheme://username:password@hostname/database/table"
 
+	_OR_
+
+    CONNECTION="scheme://username:password@hostname:port/table"
+    CONNECTION="scheme://username@hostname/table"
+    CONNECTION="scheme://username@hostname:port/table"
+    CONNECTION="scheme://username:password@hostname/table"
+
     _OR_
 
     CONNECTION="connection name"
@@ -788,8 +796,12 @@
     }
 
     if (!(share->table_name= strchr(share->database, '/')))
-      goto error;
-    *share->table_name++= '\0';
+	{
+	  share->table_name = share->database;
+	  --share->database;
+	} else {
+	  *share->table_name++= '\0';
+	}
 
     share->table_name_length= strlen(share->table_name);
 
@@ -2433,61 +2445,13 @@
 
 int ha_federatedx::delete_row(const uchar *buf)
 {
-  char delete_buffer[FEDERATEDX_QUERY_BUFFER_SIZE];
-  char data_buffer[FEDERATEDX_QUERY_BUFFER_SIZE];
-  String delete_string(delete_buffer, sizeof(delete_buffer), &my_charset_bin);
-  String data_string(data_buffer, sizeof(data_buffer), &my_charset_bin);
-  uint found= 0;
   int error;
   DBUG_ENTER("ha_federatedx::delete_row");
 
-  delete_string.length(0);
-  delete_string.append(STRING_WITH_LEN("DELETE FROM "));
-  append_ident(&delete_string, share->table_name,
-               share->table_name_length, ident_quote_char);
-  delete_string.append(STRING_WITH_LEN(" WHERE "));
-
-  for (Field **field= table->field; *field; field++)
-  {
-    Field *cur_field= *field;
-    found++;
-    if (bitmap_is_set(table->read_set, cur_field->field_index))
-    {
-      append_ident(&delete_string, (*field)->field_name,
-                   strlen((*field)->field_name), ident_quote_char);
-      data_string.length(0);
-      if (cur_field->is_null())
-      {
-        delete_string.append(STRING_WITH_LEN(" IS NULL "));
-      }
-      else
-      {
-        bool needs_quote= cur_field->str_needs_quotes();
-        delete_string.append(STRING_WITH_LEN(" = "));
-        cur_field->val_str(&data_string);
-        if (needs_quote)
-          delete_string.append(value_quote_char);
-        data_string.print(&delete_string);
-        if (needs_quote)
-          delete_string.append(value_quote_char);
-      }
-      delete_string.append(STRING_WITH_LEN(" AND "));
-    }
-  }
-
-  // Remove trailing AND
-  delete_string.length(delete_string.length() - sizeof_trailing_and);
-  if (!found)
-    delete_string.length(delete_string.length() - sizeof_trailing_where);
-
-  delete_string.append(STRING_WITH_LEN(" LIMIT 1"));
-  DBUG_PRINT("info",
-             ("Delete sql: %s", delete_string.c_ptr_quick()));
-
   if ((error= txn->acquire(share, FALSE, &io)))
     DBUG_RETURN(error);
 
-  if (io->query(delete_string.ptr(), delete_string.length()))
+  if (io->delete_row(share, table, buf))
   {
     DBUG_RETURN(stash_remote_error());
   }
@@ -3207,18 +3171,9 @@
 
 int ha_federatedx::delete_all_rows()
 {
-  char query_buffer[FEDERATEDX_QUERY_BUFFER_SIZE];
-  String query(query_buffer, sizeof(query_buffer), &my_charset_bin);
   int error;
   DBUG_ENTER("ha_federatedx::delete_all_rows");
 
-  query.length(0);
-
-  query.set_charset(system_charset_info);
-  query.append(STRING_WITH_LEN("TRUNCATE "));
-  append_ident(&query, share->table_name, share->table_name_length,
-               ident_quote_char);
-
   /* no need for savepoint in autocommit mode */
   if (!(ha_thd()->variables.option_bits & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
     txn->stmt_autocommit();
@@ -3230,13 +3185,19 @@
   if ((error= txn->acquire(share, FALSE, &io)))
     DBUG_RETURN(error);
 
-  if (io->query(query.ptr(), query.length()))
+  switch (io->delete_all_rows(share, table))
   {
+  case HA_ERR_WRONG_COMMAND:
+	DBUG_RETURN(HA_ERR_WRONG_COMMAND);
+
+  case 0:
+    stats.deleted+= stats.records;
+    stats.records= 0;
+    DBUG_RETURN(0);
+
+  default:
     DBUG_RETURN(stash_remote_error());
   }
-  stats.deleted+= stats.records;
-  stats.records= 0;
-  DBUG_RETURN(0);
 }
 
 
@@ -3307,36 +3268,6 @@
   DBUG_RETURN(to);
 }
 
-
-static int test_connection(MYSQL_THD thd, federatedx_io *io,
-                           FEDERATEDX_SHARE *share)
-{
-  char buffer[FEDERATEDX_QUERY_BUFFER_SIZE];
-  String str(buffer, sizeof(buffer), &my_charset_bin);
-  FEDERATEDX_IO_RESULT *resultset= NULL;
-  int retval;
-
-  str.length(0);
-  str.append(STRING_WITH_LEN("SELECT * FROM "));
-  append_identifier(thd, &str, share->table_name,
-                    share->table_name_length);
-  str.append(STRING_WITH_LEN(" WHERE 1=0"));
-
-  if ((retval= io->query(str.ptr(), str.length())))
-  {
-    sprintf(buffer, "database: '%s'  username: '%s'  hostname: '%s'",
-            share->database, share->username, share->hostname);
-    DBUG_PRINT("info", ("error-code: %d", io->error_code()));
-    my_error(ER_CANT_CREATE_FEDERATED_TABLE, MYF(0), buffer);
-  }
-  else
-    resultset= io->store_result();
-
-  io->free_result(resultset);
-
-  return retval;
-}
-
 /*
   create() does nothing, since we have no local setup of our own.
   FUTURE: We should potentially connect to the foreign database and
@@ -3374,7 +3305,7 @@
     tmp_txn= get_txn(thd);
     if (!(retval= tmp_txn->acquire(&tmp_share, TRUE, &tmp_io)))
     {
-      retval= test_connection(thd, tmp_io, &tmp_share);
+      retval= tmp_io->test_connection(thd, &tmp_share);
       tmp_txn->release(&tmp_io);
     }
     free_server(tmp_txn, tmp_share.s);
@@ -3401,7 +3332,7 @@
 
     tmp_io= federatedx_io::construct(thd->mem_root, &server);
 
-    retval= test_connection(thd, tmp_io, &tmp_share);
+    retval= tmp_io->test_connection(thd, &tmp_share);
 
 #ifndef DBUG_OFF
     mysql_mutex_unlock(&server.mutex);
diff -urN storage/federatedx.ori/ha_federatedx.h storage/federatedx/ha_federatedx.h
--- storage/federatedx.ori/ha_federatedx.h	2013-04-23 06:13:57.000000000 +0200
+++ storage/federatedx/ha_federatedx.h	2013-05-27 23:06:42.000000000 +0200
@@ -36,7 +36,6 @@
 #pragma interface			/* gcc class implementation */
 #endif
 
-//#include <mysql.h>
 #include <my_global.h>
 #include <thr_lock.h>
 #include "handler.h"
@@ -131,93 +130,6 @@
 typedef struct st_federatedx_row FEDERATEDX_IO_ROW;
 typedef ptrdiff_t FEDERATEDX_IO_OFFSET;
 
-class federatedx_io
-{
-  friend class federatedx_txn;
-  FEDERATEDX_SERVER * const server;
-  federatedx_io **owner_ptr;
-  federatedx_io *txn_next;
-  federatedx_io *idle_next;
-  bool active;  /* currently participating in a transaction */
-  bool busy;    /* in use by a ha_federated instance */
-  bool readonly;/* indicates that no updates have occurred */
-
-protected:
-  void set_active(bool new_active)
-  { active= new_active; }
-public:
-  federatedx_io(FEDERATEDX_SERVER *);
-  virtual ~federatedx_io();
-
-  bool is_readonly() const { return readonly; }
-  bool is_active() const { return active; }
-
-  const char * get_charsetname() const
-  { return server->csname ? server->csname : "latin1"; }
-
-  const char * get_hostname() const { return server->hostname; }
-  const char * get_username() const { return server->username; }
-  const char * get_password() const { return server->password; }
-  const char * get_database() const { return server->database; }
-  ushort       get_port() const     { return server->port; }
-  const char * get_socket() const   { return server->socket; }
-
-  static bool handles_scheme(const char *scheme);
-  static federatedx_io *construct(MEM_ROOT *server_root,
-                                  FEDERATEDX_SERVER *server);
-
-  static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
-  { return alloc_root(mem_root, size); }
-  static void operator delete(void *ptr, size_t size)
-  { TRASH(ptr, size); }
-
-  virtual int query(const char *buffer, uint length)=0;
-  virtual FEDERATEDX_IO_RESULT *store_result()=0;
-
-  virtual size_t max_query_size() const=0;
-
-  virtual my_ulonglong affected_rows() const=0;
-  virtual my_ulonglong last_insert_id() const=0;
-
-  virtual int error_code()=0;
-  virtual const char *error_str()=0;
-
-  virtual void reset()=0;
-  virtual int commit()=0;
-  virtual int rollback()=0;
-
-  virtual int savepoint_set(ulong sp)=0;
-  virtual ulong savepoint_release(ulong sp)=0;
-  virtual ulong savepoint_rollback(ulong sp)=0;
-  virtual void savepoint_restrict(ulong sp)=0;
-
-  virtual ulong last_savepoint() const=0;
-  virtual ulong actual_savepoint() const=0;
-  virtual bool is_autocommit() const=0;
-
-  virtual bool table_metadata(ha_statistics *stats, const char *table_name,
-                              uint table_name_length, uint flag) = 0;
-
-  /* resultset operations */
-
-  virtual void free_result(FEDERATEDX_IO_RESULT *io_result)=0;
-  virtual unsigned int get_num_fields(FEDERATEDX_IO_RESULT *io_result)=0;
-  virtual my_ulonglong get_num_rows(FEDERATEDX_IO_RESULT *io_result)=0;
-  virtual FEDERATEDX_IO_ROW *fetch_row(FEDERATEDX_IO_RESULT *io_result)=0;
-  virtual ulong *fetch_lengths(FEDERATEDX_IO_RESULT *io_result)=0;
-  virtual const char *get_column_data(FEDERATEDX_IO_ROW *row,
-                                      unsigned int column)=0;
-  virtual bool is_column_null(const FEDERATEDX_IO_ROW *row,
-                              unsigned int column) const=0;
-
-  virtual size_t get_ref_length() const=0;
-  virtual void mark_position(FEDERATEDX_IO_RESULT *io_result,
-                             void *ref)=0;
-  virtual int seek_position(FEDERATEDX_IO_RESULT **io_result,
-                            const void *ref)=0;
-
-};
-
 
 class federatedx_txn
 {
@@ -451,9 +363,3 @@
 
 extern bool append_ident(String *string, const char *name, uint length,
                          const char quote_char);
-
-
-extern federatedx_io *instantiate_io_mysql(MEM_ROOT *server_root,
-                                           FEDERATEDX_SERVER *server);
-extern federatedx_io *instantiate_io_null(MEM_ROOT *server_root,
-                                          FEDERATEDX_SERVER *server);

Follow ups