Hello,

I have tried to setup the new version of Twitter module (7.x-5.4) few times, but every time there is the error:

PDOException: SQLSTATE[07002]: [Microsoft][SQL Server Native Client 10.0]COUNT field incorrect or syntax error: SELECT * FROM {twitter_account} WHERE twitter_uid = :id OR screen_name = :id; Array ( [:id] => ) in twitter_account_load() (line 83 of ...\sites\all\modules\twitter\twitter.inc).

The error is coming up after filling the twitter settings and trying to ad twitter account. If I don't fill the settings there is not error.

I use Sql Server database.

I have changed again to 7.x-3.3 and the module works perfect. But there is a notice that we have to update to 7.x-5.4 sooner or later.

Thank you for your help.

CommentFileSizeAuthor
#4 duplicate_placeholders-1905324-4.patch895 bytesomegamonk
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

juampynr’s picture

Assigned: katya n » Unassigned
Status: Active » Postponed (maintainer needs more info)

I have no clue why you are getting that error. SqlServer seems to choke at this query:

  if ($values = db_query('SELECT *
                          FROM {twitter_account}
                          WHERE twitter_uid = :id
                            OR screen_name  = :id',
                          array(':id' => $id))->fetchAssoc()) {

I can only suggest you to debug the error further.

kimberlydb’s picture

I too got this error when first setting up twitter, after a bit of debugging, the query dies because $id is empty and the ms sql query doesn't know what to do with this since it thinks we are asking

Select * FROM {twitter_account} WHERE twitter_uid = OR screen_name =;

I fixed it by changing the following:

if (!empty($id) && $values = db_query('SELECT *
                          FROM {twitter_account}
                          WHERE twitter_uid = :id
                            OR screen_name  = :id',
                          array(':id' => $id))->fetchAssoc()) {
...

EDIT: I am then able to add my twitter accounts. However when it returned back I got another error, which I realized is that the replacement of :id doesn't seem to be working for mssql at all, so I then changed it to:

  if (!empty($id) && $values = db_query('SELECT *
                          FROM {twitter_account}
                          WHERE twitter_uid = ' . $id .
                          '  OR screen_name  = ' . $id
                          )->fetchAssoc()) {
...

which, while far uglier, gets the job done.

EDIT: So upon more investigation, it dies because we are using $id as both possibly numeric or a string, because it is either the twitter_uid or the screen_name when calling this function. So I changed it a bit more to appease mssql...

$query = '';
if( is_numeric($id) ) {
  $query = 'SELECT * FROM {twitter_account} WHERE twitter_uid = ' . $id;
}
else {
  $query = 'SELECT * FROM {twitter_account} WHERE screen_name = \'' . $id . '\'';
}

if (!empty($id) && $values = db_query($query)->fetchAssoc()) {

If there's a better solution, let me know.

david_garcia’s picture

Hi I was just reviewing this to turn it into a patch and since then found something that my be a hint on what the original error is really about:

https://drupal.org/node/2009886

and

https://drupal.org/node/1598924

It looks as though you cannot use the same placeholder more than once in a query.

omegamonk’s picture

Status: Postponed (maintainer needs more info) » Needs review
FileSize
895 bytes

After some digging in to this issue a bit....

Per the Drupal database placeholder documentation, "A query may have any number of placeholders, but all must have unique names even if they have the same value.".

I included a patch to change the placeholder names in the affected code, but I didn't have a chance to test it out.

juampynr’s picture

Title: Can not ad twitter account » Cannot add twitter account
Version: 7.x-5.4 » 7.x-5.x-dev
Status: Needs review » Fixed

Made a small change to the patch format and committed it. Thanks!

http://drupalcode.org/project/twitter.git/commit/1b91dfa

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.