mrjgreen/db-sync

Syntax error or access violation: 1064

Closed this issue · 2 comments

Hi,

I'm trying to sync two remote Db's programatically and am getting the following error:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') < ()) t limit 1' at line 1 host: dev.workspace driver: mysql username: root charset: utf8 collation: utf8_general_ci SQL: select CONCAT(COALESCE(LOWER(CONV(BIT_XOR(CAST(CONV(SUBSTR(MD5(CONCAT_WS('#', id, parent_id, name, code, description)),17,16),16,10) AS UNSIGNED)), 10, 16)), 0),COALESCE(LOWER(CONV(BIT_XOR(CAST(CONV(SUBSTR(MD5(CONCAT_WS('#', id, parent_id, name, code, description)),1,16),16,10) AS UNSIGNED)), 10, 16)), 0)) from (select id, parent_id, name, code, descriptionfromcashbuild_store.levels where () < ()) t limit 1

The issue seems to be caused by the where clause at the end of the statement, I managed to track it down to getWhereEnd in the Table class, but have not been able to resolve it.

This is the script running the sync:

`<?php

require 'vendor/autoload.php';
use DbSync\DbSync;
use DbSync\Transfer\Transfer;
use DbSync\Table;
use DbSync\WhereClause;
use DbSync\Hash\ShaHash;
use DbSync\ColumnConfiguration;

class Sync {
public function test() {

   $sync = new DbSync(new Transfer(new ShaHash(), 1024, 8));

    $sync->dryRun(false);

    $sync->delete(false); //This should get set to true for our use case

    $sourceCred = array(
        'host'      => '',
        'driver'    => 'mysql',
        'username'  => '',
        'password'  => '',
        'charset'   => 'utf8',
        'collation' => 'utf8_general_ci',
    );

    $sourceConnection = (new \Database\Connectors\ConnectionFactory())->make($sourceCred); //This is important

    $targetCred = array(
        'host'      => '',
        'driver'    => 'mysql',
        'username'  => 'root',
        'password'  => '',
        'charset'   => 'utf8',
        'collation' => 'utf8_general_ci',
    );

    $targetConnection = (new \Database\Connectors\ConnectionFactory())->make($targetCred);

    $sourceDb = 'cashbuild_live';
    $sourceTable = 'levels';

    $targetDb = 'cashbuild_store';
    $targetTable = 'levels';

    $sourceTable = new Table($sourceConnection, $sourceDb, $sourceTable);
    $targetTable = new Table($targetConnection, $targetDb, $targetTable);
    return $sync->sync($sourceTable, $targetTable); //Returns an object with the number of changes made

}

}
`

Any help would be appreciated.
Regards

Hi, It looks like you don't have a primary key on your table.

Ah, that was indeed the problem, can't believe I never noticed that.

Thanks for the speedy reply!