When attempting to create a content type with the attributes of being both a group and content of a group, og fails when using SQL Server (MS SQL). The content type can be created, but when trying to add content of that type, the following error appears:

PDOException: SQLSTATE[22018]: [Microsoft][SQL Server Native Client 10.0][SQL Server]Conversion failed when converting the nvarchar value '2.0' to data type int.: SELECT base.[gid] AS [gid], base.[etid] AS [etid], base.[entity_type] AS [entity_type], base.[label] AS [label], base.[state] AS [state], base.[created] AS [created] FROM {og} base WHERE ( ([base].[gid] IN (:db_condition_placeholder_0, :db_condition_placeholder_1)) ); Array ( [:db_condition_placeholder_0] => 1.0 [:db_condition_placeholder_1] => 2.0 ) in EntityAPIController->query() (line 143 of \sites\all\modules\entity\includes\entity.controller.inc).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

amitaibu’s picture

Status: Active » Postponed (maintainer needs more info)

Did you try it with the -dev version?

kpastore’s picture

Thanks for the response. Yes, I tried it with the latest dev version, only to receive the following error:

PDOException: SQLSTATE[25000]: [Microsoft][SQL Server Native Client 10.0][SQL Server]Cannot roll back savepoint_1. No transaction or savepoint of that name was found.: ROLLBACK TO SAVEPOINT savepoint_1; Array ( ) in user_save() (line 591 of \modules\user\user.module).

It was able to at least get to the page to create the subgroup, but when I went to save it, that is when the error appeared.

Error only occurs when Group type: Group type is selected. When Not a group type is selected, the content gets created. Although, it is Group type that is needed.

kpastore’s picture

Update: With the latest -dev installed, a regular group cannot be created either. Same 'rollback' error as above.

amitaibu’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
Status: Postponed (maintainer needs more info) » Active

@kpastore,

I suspect this isn't an OG issue, but related to dbtng. As I don't know MS SQL I can't help much; Maybe this issue is related? #1007830: Nested transactions throw exceptions when they got out of scope

kpastore’s picture

After attempting to create a node within a regular group (not a subgroup), using the latest -dev, the original error has returned on all pages but references an OG module function:

PDOException: SQLSTATE[22018]: [Microsoft][SQL Server Native Client 10.0][SQL Server]Conversion failed when converting the nvarchar value '3.0' to data type int.: SELECT og.[gid] AS [gid], og.[gid] AS [og_gid] FROM {og} og WHERE ( ([gid] IN (:db_condition_placeholder_0)) AND ([state] IN (:db_condition_placeholder_1)) ); Array ( [:db_condition_placeholder_0] => 3.0 [:db_condition_placeholder_1] => 1 ) in og_get_group_ids() (line 1405 of \sites\all\modules\og\og.module).

along with the following:

Warning: Cannot modify header information - headers already sent by (output started at \includes\common.inc:2565) in drupal_send_headers() (line 1039 of D:\vhosts\autodesk\includes\bootstrap.inc).

When OG is disabled, the errors disappear, so I do believe there may be an issue here.

It seems that the query being performed is pulling an 'int' (og.gid or og.etid) from the db and somehow it is getting converted to 'nvarchar' before being returned as an 'int' in $return (line 1419).

So my question would be, is it the function that is converting it, or is it the sql driver?

amitaibu’s picture

> or is it the sql driver?

Sounds like the driver. because this works properly on mysql. Try casting $query_etids in og_get_group_ids() to integer just before ->condition('nid', $query_etids, 'IN');.

AndrewS’s picture

Hi,

Definately not the nicest workaround, but for those like me without much of a clue of PHP/Drupal - flicking over the data type from 'int' to 'decimal' on table 'dbo.og' in SQL Server bypasses the conversion error.

On a sidenote (and this is completely grasping at straws here), og.field.inc's og_field_schema function describes 'gid' field as a float type.
Not sure how or even if this influences things, but given that both MySQL and SQL Server create this field as an int on the database it looks to be out of place.

Thanks,
A

Update:

Looks like two different issues:

1. 7.x-1.0: As described above; when using SQL Server as a database backend.

2. 7.x-1.x-dev:
a. ROLLBACK error: caused by Drupal attempting to roll back a savepoint after the savepoint has been committed. (rollback kicked off in user.module, user_save() function
b. Above exception is triggered by:
exec sp_executesql N'SELECT og_membership.[id] AS [entity_id], og_membership.[name] AS [bundle], @P1 AS entity_type, NULL AS revision_id
FROM
og_membership og_membership
WHERE ( ([og_membership].[entity_type] = @P2) AND ([og_membership].[etid] = @P3) AND ([og_membership].[gid] = @P4) )',N'@P1 nvarchar(13),@P2 nvarchar(4),@P3 nvarchar(1),@P4 nvarchar(3)',N'og_membership',N'user',N'1',N'1.0'

with exception message

exception 'Exception' with message 'Group membership for entity user with ID 1 for group ID 19.0 () already exists

Going into admin/config/group/fields and deleting the "Groups audience" under the "User Entity" makes the exception go away, so it looks like the issue needs to be tracked there.

Hope this helps

shancock’s picture

I have experienced all the same issues as above using MSSQL. I think this is an awesome module and would greatly appreciate someone creating a patch to use with MSSQL! I had to uninstall due to the recurring errors.

JayDarnell’s picture

This issue still appears to be happening in D7.12 (Acquia distribution) when using MSSQL. Organic groups is a core module I will need to complete my current project. Do either of the organic groups contributors have a suggestion on how we should handle this problem? AndrewS made a suggestion that seems like it could work but I'm hesitant to modify the datatypes for the fields on the og table unless I know that is a truly acceptable solution.

For clarity I should add that I received the following error from the base D7.12 Acquia install after the following steps:

Organic Groups - http://drupal.org/project/og
Entity API - http://drupal.org/project/entity

1. Install both modules
2. Enable the following (in order):
- Entity API
- Organic Groups
- Organic Groups API

3. Create new content type called: Group
- Under the group tab at the bottom of the content creation page set this new content type as a "Group Type"

4. Modify Article content type setting it up as "Group Content"

5. Create a new group called group #1

6. Create a new article and assign it to group #1

Error Received:

PDOException: SQLSTATE[22018]: [Microsoft][SQL Server Native Client 10.0][SQL Server]Conversion failed when converting the nvarchar value '1.0' to data type int.: SELECT og.[gid] AS [gid], og.[gid] AS [og_gid] FROM {og} og WHERE ( ([gid] IN (:db_condition_placeholder_0)) AND ([state] IN (:db_condition_placeholder_1)) ); Array ( [:db_condition_placeholder_0] => 1.0 [:db_condition_placeholder_1] => 1 ) in og_get_group_ids() (line 1498 of C:\Users\dar016900\Documents\My Web Sites\Acquia Drupal 7\sites\all\modules\contrib\og\og.module).

citlacom’s picture

Same error happen to me when editing any content type that has a group audience field, going to the node/nid/edit page raise the next error:

PDOException: SQLSTATE[42000]: [Microsoft][SQL Server Native Client 10.0][SQL Server]Error converting data type nvarchar to bigint.: SELECT base.[gid] AS [gid], base.[etid] AS [etid], base.[entity_type] AS [entity_type], base.[label] AS [label], base.[state] AS [state], base.[created] AS [created] FROM {og} base WHERE ( ([base].[gid] IN (:db_condition_placeholder_0)) ); Array ( [:db_condition_placeholder_0] => 1.0 ) in EntityAPIController->query() (line 152 of D:\www\splenda\www\sites\all\modules\contrib\entity\includes\entity.controller.inc).

After some debug I look that this error is weird, the reason is that the

function og_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $base) {

receive the default $items array with the values of the index 'gid' represented as a decimal number. E.g. Array ( [gid] => 1.0 [state] => 1 [created] => 1339439151 )

If I do a casting to (int) when building the $gids array befora call og_load_multiple($gids) this error is fixed but probably we should focus on the cause of the error and my question is: Why the $items array pass the gid as decimal values?

I attach a small patch that resolve the issue when editing a node with field group audience. Probably there are other cases where this happen and for better fix we should create a casting of all the $gids array before calling og_load_multiple($gids).

citlacom’s picture

Finally after more researching on this problem and finding that the previous patch only fix the issue when editing a OG content node but not in other scenarios, E.g. when loaded a OG content node through Rules, I decided to look other approaches to do the casting and hopefully the hook_query_alter() is the better solution I could found.

Here I attach the new patch, so ignore the previous implementation because this patch will resolve previous bug but also other cases when a OG content get loaded.

citlacom’s picture

Status: Active » Needs review

Finally after deep research and debug we found that this issue is directly related with #1277842: Data type of gid column in og_field_schema is float instead of int the problem is that the group_audience field has a wrong type for the group audience gid (declared as float). This accepts the casting in MySQL but raise exception in sqlite and MSSQL server.

This will be resolved if before installing OG you fix the schema with the patch http://drupal.org/files/issues/0001-Fixes-1277842.patch but if you alredy installed the module and created many content types and content that uses field group_audience the thing is more complex to resolve because many fields will have wrong data type (float). I created a patch http://drupal.org/files/OG-Fix-the-group-audience-float-schema-issue-127... that could fix that missing fields.

Status: Needs review » Needs work