Import is successful & content type created but all CCK fields blank.
Isolated very simple test case with only text fields:
Member Name,title,Member Name Abbreviation
"Dedicon, lectuur en informatie","Dedicon Netherlands","Dedicon"
"Swedish DAISY Consortium","Swedish DAISY Consortium","SEDC"

Log:
Type php
Date Friday, May 15, 2009 - 16:01
Location http://www.digitaltalkingbook.com/d/admin/content/node_import/10/continue
Referrer http://www.digitaltalkingbook.com/d/admin/content/node_import/10
Message mysqli_real_escape_string() expects parameter 2 to be string, array given in /home/digitbg5/public_html/d/includes/database.mysqli.inc on line 323.
Severity error

CommentFileSizeAuthor
node_import-node_member-10.txt81.16 KBk8
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ncameron’s picture

Having the same problem. Date, taxonomy and body fields are all fine, but CCK text fields are coming up blank

ncameron’s picture

I was going to have a crack at debugging this, but not quite sure where to start as I am unsure of the overall architecture of the code and modules.

It looks like a call to the function db_escape_string() which is causing the problem. My question is where is this being called from?

We need to a lot importing fairly urgently, so I'm willing to help as much as possible.

Thanks,

Neil

ncameron’s picture

We were desperate to get this working at all costs and came up with this work around. Please read the disclaimer below:

****** IMPORTANT ********
This work around is not just hacky but damn right dangerous. It disables a crucial function which helps to stop XSS attacks. If you do use this please:

- Only use it to import data you are 100% sure has no XSS attacks (if you don't know what this is, find out)
- As soon as you finish importing, revert to the original file.
*************************

OK, lets get cracking.

In includes/database.mysql.inc on line 332 replace:

<?php
function db_escape_string($text) {
  global $active_db;
  return mysql_real_escape_string($text, $active_db);
}
?>

with

<?php
/**
 * Prepare user input for use in a database query, preventing SQL injection attacks.
 */
function db_escape_string($text) {
  global $active_db;
  //return mysql_real_escape_string($text, $active_db);
  return naddda($text, $active_db);
}

function naddda($text, $active_db){
	return $text;
	return $active_db;
}
?>

Run the import.

Revert the original file.

I can't repeat enough, this is a quick, dirty and dangerous way to work around. Use at your own risk. I hope we can come up with a proper solution soon.

Cheers,

Neil

edward.peters’s picture

I had exactly the same problem! Very frustrating. Hope it can be sorted out as it will be a really great module. Thanks to those who have produced it!

fc-mv08’s picture

Same problem of CCK blank fields and the crack #3 doesn't work...

Daniel A. Beilinson’s picture

Okay, changes from #3 need make with includes/database.mysqli.inc, not with database.mysql.inc, because we have error from mysqli file. Works for me.

Junro’s picture

same problem, text fields are empty...

Daniel A. Beilinson’s picture

Try to use crack from #3 with database.mysqli.inc and without

Junro’s picture

using crack from #3:

user warning: 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 's page cache is enabled, this event won't be generated for pages served from cac' at line 1 query: SELECT s.lid, t.translation, s.version FROM locales_source s LEFT JOIN locales_target t ON s.lid = t.lid AND t.language = 'fr' WHERE s.source = 'Note that if drupal's page cache is enabled, this event won't be generated for pages served from cache.' AND s.textgroup = 'default' in /home/pariscin/www/modules/locale/locale.module on line 365.
user warning: 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 's page cache is enabled, this event won't be generated for pages served from cac' at line 1 query: INSERT INTO locales_source (location, source, textgroup, version) VALUES ('/sites/default/files/imagecache/affiches_fiches/affiches_us/inglorious_basterds_us.jpg', 'Note that if drupal's page cache is enabled, this event won't be generated for pages served from cache.', 'default', '6.12') in /home/pariscin/www/modules/locale/locale.module on line 381.
user warning: 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 approved then this event won't be triggered.' AND s.textgroup = 'default'' at line 1 query: SELECT s.lid, t.translation, s.version FROM locales_source s LEFT JOIN locales_target t ON s.lid = t.lid AND t.language = 'fr' WHERE s.source = 'A user has subscribed to a group and is approved. If the user isn't approved then this event won't be triggered.' AND s.textgroup = 'default' in /home/pariscin/www/modules/locale/locale.module on line 365.
user warning: 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 approved then this event won't be triggered.', 'default', '6.12')' at line 1 query: INSERT INTO locales_source (location, source, textgroup, version) VALUES ('/sites/default/files/imagecache/affiches_fiches/affiches_us/inglorious_basterds_us.jpg', 'A user has subscribed to a group and is approved. If the user isn't approved then this event won't be triggered.', 'default', '6.12') in /home/pariscin/www/modules/locale/locale.module on line 381.

Even if it's working, we can use it on a production site, unless to set the site off-line.

Have you got this too?

Daniel A. Beilinson’s picture

No, I can't see this. But my locale module switched off. What kind of fields did you import?

Junro’s picture

Text fields
Node reference fields
Date fields

With Node reference et date fields, i had to set on Select widget to make the import work.

But all import dates are 1970, so wird....

this warning message i've got above is on nodes who contains the text fields.

Daniel A. Beilinson’s picture

Sorry, I don't know.

Btw, about date: date must be select list too, but for me all empty values is 01.01.2009. :-(

Junro’s picture

My date is set to select list too, and I don't have empty values to import. Whatever the date I import, it willshow 1970! lol

Daniel A. Beilinson’s picture

Maybe it's date's problem? Try to use newer version.

Junro’s picture

I do, always do with Date lol so much problem with it! :)

Daniel A. Beilinson’s picture

Yeah, bull's-eye!

oadaeh’s picture

Why not just do:

/**
* Prepare user input for use in a database query, preventing SQL injection attacks.
*/
function db_escape_string($text) {
  //global $active_db;
  //return mysql_real_escape_string($text, $active_db);
  return $text;
}

because that's all that's happening with the fake function.

Really, the best thing to do is to figure out at what point this code is being called incorrectly and change how it's being called, rather than promoting the hack.

It happens for me when I have a date field in the content type, even if that field is not being used. So, I'm guessing that this module is receiving or retrieving data from the date field in a format it doesn't expect, and isn't doing any error checking. I'll probably be back with more information later today, as I need to get this working correctly today.

Junro’s picture

Hello,

When a field is used with more than one node type, the field is not anymore in the table of the node type where the field has been created. It owns his own table.

Maybe node import works only with fields inside the table of the node type whe choose to import.

I just said thaht because ALL my fields inside my node type have been imported, and all fields with their own table have a problem.

oadaeh’s picture

@Junro: Interesting thought, and it might be another clue. I doubt that's the complete answer, however. I have only two node types, and neither one shares any fields, and I have problems importing all of my data.

Daniel A. Beilinson’s picture

@oadaeh: Thank you.

k8’s picture

OK still critical here since have so much more to import and still must do the workaround below.
Trying to import a date field is the problem that causes no error message but all other fields to be blank.

So can anyone specify what content type options work to successfully import date fields - just simple yyyy-dd-mm fields into CCK date fields?

My WORKAROUND:
1. Create content field "Start_date_text" of type text
2. Import date content from CSV file (currently just yyyy-mm-dd values)
3. Create content field "Start_date_date" of type date
4. Run SQL query Update table "member.." set Start_date_date = Start_date_text;

Thus Drupal thinks it has a CCK field of type date and acan do Drupal date arithmetic and operations on it.

oadaeh’s picture

IIRC, this totally worked for me the last time I tried it.

I am using the latest dev version of this module.

What I had to do was to set the date field to custom and specify the format to be the same as the text being imported.

I'm still waiting for the final scrub on the data to do the final and complete import, so I'm in a holding pattern for now.

I'll try to update this issue when I complete the process to let everyone know what my final results were.

makbeta’s picture

Fix #17 has worked for me.
I've attempted to track down the actual issue, but no luck.
I've got as far as to figure out that the source of the problem is that the string of data passed to db_query function (called several times in the main module & in the api file) is passed as an array instead of a string. A more elegant and less risky update to the db_escape_string function is as follows.

<?php
function db_escape_string($text) {
if (is_array($text)) {$text = $text[0];}
  global $active_db;
  return mysql_real_escape_string($text, $active_db);
}
?>

This ensures that the function behaves normally under normal circumstances & if we encounter an array only it's first element will be used. This of course does not address the core issue of this problem, but I hope someone who knows this modules code more intimately can make use of this information and make a real fix to the module.

HorsePunchKid’s picture

Subscribing.

CarbonPig’s picture

Subscribe and ? -

#17 - where do you put this php?

Thanks,

CarbonPig

Daniel A. Beilinson’s picture

@CarbonPing: Please, look at #3

oadaeh’s picture

In light of the recent subscriptions, I wanted to say that I did get this working, w/o using either #3 or #17. It's been a few months now, but IIRC, I got it working by using the following:

  • The 6.x-1.x-dev version of Node import.
  • The 6.x-2.4 version of Date.
  • The fixes to date.inc from this thread.
  • A 'Widget type' set to 'Text Field with custom input format' before the import. (I set it back to 'Text Field with Date Pop-up calendar' after the import with out any problems.)
  • The same custom date configuration as the data being imported for both the content type and the import (step 5 of 8).

I don't know which piece of the puzzle fixed the problem for me, or if it required all of them, but I do know that I was finally able to get something like 15,000 dates imported w/o any problem.

ozecho’s picture

The patch in #23 worked for me applying it to database.mysql.inc which is where I was getting my error.

Thanks for the workaround, but have we worked out what is causing it? is it date CCK fields?

twooten’s picture

I also made the changes in #23 and my data started importing. Thank you makbeta!

daliverse’s picture

Subscribing.

anonymous07’s picture

Subscribe .... been going crazy trying to get D6 upgrade from D5 working (import CSV into date fields for scheduled publishing and unpublishing of nodes) and it might very well be this issue.

EDIT: SOLVED! (Node_Import + CCK + Date + Scheduler + Rules)

Used the clues from post #27 above AND had to disable Date Popup Module (I am not entering any dates manually anyway, they are all coming from the CSV file being imported or being computed by a PHP rule.)

Thanks everyone

nally’s picture

Subscribe

couash’s picture

Variant of #23 for mysqli

change the function 'db_escape_string' in includes/database.mysqli.inc to read like this:


function db_escape_string($text) 
{
	if (is_array($text))
	{
		$text = $text[0];
	}
  	global $active_db;
  	return mysqli_real_escape_string($active_db, $text);
}

Worked for me. Credit goes to makbeta.

*Note for those unfamiliar with php code, don't put the php tags! ;-)

Cheers!

Encarte’s picture

subscribing

CarbonPig’s picture

subscribe again - continually having text fields that are half imported.