CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Import (Moderator: Yashodha Chaku) »
  • SQL Import Syntax Issue
Pages: [1]

Author Topic: SQL Import Syntax Issue  (Read 6693 times)

cdoctor

  • I’m new here
  • *
  • Posts: 15
  • Karma: 0
SQL Import Syntax Issue
September 06, 2012, 02:35:22 pm
In my civicrm database I have uploaded a table with contacts to import into civicrm.  However, when attempting to import the contacts I receive the DB Error: syntax error message.

The query I use in civicrm to import the data (SELECT * FROM test_civicrm.first_import;) runs successfully in mysql and phpmyadmin to select all of the records in that table. 

Below is additional information on the error and what I am running.

Civicrm - 4.2
MySQL - 5.1.41

Database Error Code: 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 'ADD COLUMN _status VARCHAR(32) DEFAULT 'NEW' NOT NUL' at line 2, 1064
Additional Details:
Array
(
    [callback] => Array
        (
           
  • => CRM_Core_Error
  • [1] => handle
            )

       
Code: [Select]
=> -2
    [message] => DB Error: syntax error
    [mode] => 16
    [debug_info] => ALTER TABLE
                       ADD COLUMN _status VARCHAR(32)
                            DEFAULT 'NEW' NOT NULL,
                       ADD COLUMN _statusMsg TEXT,
                       ADD COLUMN _id INT PRIMARY KEY NOT NULL
                               AUTO_INCREMENT [nativecode=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 'ADD COLUMN _status VARCHAR(32)
                            DEFAULT 'NEW' NOT NUL' at line 2]
    [type] => DB_Error
    [user_info] => ALTER TABLE
                       ADD COLUMN _status VARCHAR(32)
                            DEFAULT 'NEW' NOT NULL,
                       ADD COLUMN _statusMsg TEXT,
                       ADD COLUMN _id INT PRIMARY KEY NOT NULL
                               AUTO_INCREMENT [nativecode=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 'ADD COLUMN _status VARCHAR(32)
                            DEFAULT 'NEW' NOT NUL' at line 2]
    [to_string] => [db_error: message="DB Error: syntax error" code=-2 mode=callback callback=CRM_Core_Error::handle prefix="" info="ALTER TABLE
                       ADD COLUMN _status VARCHAR(32)
                            DEFAULT 'NEW' NOT NULL,
                       ADD COLUMN _statusMsg TEXT,
                       ADD COLUMN _id INT PRIMARY KEY NOT NULL
                               AUTO_INCREMENT [nativecode=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 'ADD COLUMN _status VARCHAR(32)
                            DEFAULT 'NEW' NOT NUL' at line 2]"]
)

JonGold

  • Ask me questions
  • ****
  • Posts: 638
  • Karma: 81
    • Palante Technology
  • CiviCRM version: 4.1 to the latest
  • CMS version: Drupal 6-7, Wordpress 4.0+
  • PHP version: PHP 5.3-5.5
Re: SQL Import Syntax Issue
September 06, 2012, 02:47:49 pm
The issue is that the "ALTER TABLE" portion of the statement expects a table name, and none seems to be provided.  I'll spend a couple more minutes looking at the code, but the solution is probably above my pay grade.

Jon
« Last Edit: September 06, 2012, 02:50:50 pm by JonGold »
Sign up to StackExchange and get free expert CiviCRM advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

JonGold

  • Ask me questions
  • ****
  • Posts: 638
  • Karma: 81
    • Palante Technology
  • CiviCRM version: 4.1 to the latest
  • CMS version: Drupal 6-7, Wordpress 4.0+
  • PHP version: PHP 5.3-5.5
Re: SQL Import Syntax Issue
September 06, 2012, 03:12:08 pm
So I'm stuck since I don't have a dev environment on the computer I'm on.  But if anyone else wants to take a peek...

The code in question is in CRM/Import/Form/DataSource.php.  The postProcess function calls _prepareImportTable at line 316.  On line 315 it SHOULD be getting $importTableName, but I guess it's not.  Someone with debugging enabled can take it from there.

Based on lines 306-312, I suspect that line 315 wasn't changed when the "hack to prevent multiple tables" was added.  If trut, line 315 should be changed from:
      $importTableName = $this->get('importTableName');

to:
      $importTableName = $this->_params['import_table_name']

...but a) I don't have a way to test that, and b) my understanding of this code without watching it run is pretty shaky.  So I'm not going to write that patch.  cdoctor, if you wanted to try making that edit on a NON-PRODUCTION version of your db and report if it fixes the problem, that would be awesome!

Jon
Sign up to StackExchange and get free expert CiviCRM advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

cdoctor

  • I’m new here
  • *
  • Posts: 15
  • Karma: 0
Re: SQL Import Syntax Issue
September 06, 2012, 03:38:24 pm
Jon:

That is a negative with the change in code - Parse error: syntax error, unexpected T_VARIABLE.

John Q. Public

  • I’m new here
  • *
  • Posts: 6
  • Karma: 0
  • CiviCRM version: 4.2.4
  • CMS version: Drupal 7
  • MySQL version: 5.1
  • PHP version: 5.3
Re: SQL Import Syntax Issue
October 03, 2012, 01:30:27 pm
I'm seeing the same thing. CiviCRM 4.2, PHP 5.3.2, MySQL 5.1.63. Contact import using SQL query, "select * from <table_name>;" (table is in the civicrm db). At first I was getting the same error as cdoctor where the ALTER TABLE was missing a table name. I likewise followed JonGold's suggestion to get the import table name from the _params ($importTableName = $this->_params['import_table_name']) since get('importTableName') was not returning anything, and _params did contain a table name. But that doesn't work either and produces a no such table error.

I can't post the log output because this forum thinks it is an external link, but the message is "DB Error: no such table".

This worked in 4.1. It looks like the table is not being created.

Is this working for anyone or has anyone made any progress on a fix? Thanks!

John Q. Public

  • I’m new here
  • *
  • Posts: 6
  • Karma: 0
  • CiviCRM version: 4.2.4
  • CMS version: Drupal 7
  • MySQL version: 5.1
  • PHP version: 5.3
Re: SQL Import Syntax Issue
October 03, 2012, 03:46:12 pm
Found the 4.2.2 upgrade -- it fixed this issue. Thank you!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Import (Moderator: Yashodha Chaku) »
  • SQL Import Syntax Issue

This forum was archived on 2017-11-26.