Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with pdo FetchField with sqlsrv #234

Closed
diogotoscano opened this issue May 2, 2016 · 5 comments
Closed

Problem with pdo FetchField with sqlsrv #234

diogotoscano opened this issue May 2, 2016 · 5 comments
Assignees
Labels
enhancement mssqlnative Native driver for SQL Server driver (Tier 1) pdo The PHP PDO Driver (Tier 2)
Milestone

Comments

@diogotoscano
Copy link

On method FetchField changed:
if (isset($arr['native_type']) && $arr['native_type'] <> "null") {
$o->type = $arr['native_type'];
}
else {
$o->type = adodb_pdo_type($arr['pdo_type']);
}

to:

    if (isset($arr['sqlsrv:decl_type']) && $arr['sqlsrv:decl_type'] <> "null") {
        $o->type = $arr['sqlsrv:decl_type'];
    }
    elseif (isset($arr['native_type']) && $arr['native_type'] <> "null") {
        $o->type = $arr['native_type'];
    }
    else {
        $o->type = adodb_pdo_type($arr['pdo_type']);
    }

DUe to sqlsrv the type come in the index "sqlsrv:decl_type"

@mnewnham
Copy link
Contributor

mnewnham commented May 7, 2016

According to This page, the PHP type is returned in the 'native_type' field. Are you saying that the value in that field is incorrect? could you give a sample of code where the data is being returned inappropriately please. Also what version of PHP, what version of ADOdb, platform, driver etc.

@diogotoscano
Copy link
Author

Not incorrect, but inaccurate. As you can see at the documentation:
driver:decl_type Specifies the SQL type used to represent the column value in the database. If the column in the result set is the result of a function, this value is not returned by PDOStatement::getColumnMeta.

The index native_type can't tell if a type is varchar, nvarchar, char or nchar. Always come with "string".

As you can see in my teste attached

mssql.zip

The output:
Array
(
[flags] => 0
[sqlsrv:decl_type] => int
[native_type] => string
[table] =>
[pdo_type] => 2
[name] => codigo
[len] => 10
[precision] => 0
)

Array
(
[flags] => 0
[sqlsrv:decl_type] => varchar
[native_type] => string
[table] =>
[pdo_type] => 2
[name] => teste1
[len] => 222
[precision] => 0
)

Array
(
[flags] => 0
[sqlsrv:decl_type] => nvarchar
[native_type] => string
[table] =>
[pdo_type] => 2
[name] => teste2
[len] => 222
[precision] => 0
)

Array
(
[flags] => 0
[sqlsrv:decl_type] => nchar
[native_type] => string
[table] =>
[pdo_type] => 2
[name] => teste3
[len] => 2
[precision] => 0
)

But we need to know the difference between varchar and nvarchar to change the SQL to protect with N''

@mnewnham mnewnham added enhancement mssqlnative Native driver for SQL Server driver (Tier 1) pdo The PHP PDO Driver (Tier 2) labels May 20, 2016
@mnewnham mnewnham added this to the v5.21 milestone May 20, 2016
@mnewnham mnewnham self-assigned this May 20, 2016
mnewnham added a commit that referenced this issue May 20, 2016
…type, see #234

1. The fetchfield method fails if a default value (-1) is sent to the method
2. SQL Server returns driver specific field information which should be used 
instead of the generic PDO data types
3. Field object information is cached to reduce repetitive reads of field data
information
mnewnham added a commit that referenced this issue May 21, 2016
If the database is Microsoft SQL Server, use the sqlsrv native data types (sqlsrv:decl_type) instead of the PDO native type for improved field type recognition, This fix has been migrated to the pdo_sqlsrv driver in V5.21 (see #245,  see #247,  see #245,  see #250)
@dregad
Copy link
Member

dregad commented May 25, 2016

@mnewnham you targeted this at 5.21, yet you committed cb5f1c7 to 5.20.5 branch - should I change the milestone ?

dregad pushed a commit that referenced this issue May 25, 2016
If the database is Microsoft SQL Server, use the sqlsrv native data
types (sqlsrv:decl_type) instead of the PDO native type for improved
field type recognition.

This fix has been migrated to the pdo_sqlsrv driver in v5.21 (see #245,
#247, #245, #250)
@mnewnham
Copy link
Contributor

No, I'm (amazingly) ahead of schedule on this

@dregad
Copy link
Member

dregad commented May 26, 2016

I'm not sure I understand what you mean by that. I see 2 sets of fixes

So IMO either the former is the fix and the milestone of this issue should be is 5.20.5, or the proper fix is the latter, in which case shouldn't cb5f1c1 not be applied in 5.20.5.

Please clarify

dregad pushed a commit to dregad/ADOdb that referenced this issue May 27, 2016
1. The fetchfield method fails if a default value (-1) is sent to the
   method
2. SQL Server returns driver specific field information which should be
   used instead of the generic PDO data types
3. Field object information is cached to reduce repetitive reads of
   field data information

Fixes ADOdb#251, ADOdb#234
dregad added a commit to dregad/ADOdb that referenced this issue May 27, 2016
Follow-up on c4b339cb12b9ccdea54a1ff42aa853d89e97188b. See ADOdb#251, ADOdb#234.
dregad pushed a commit to dregad/ADOdb that referenced this issue Aug 28, 2016
1. The fetchfield method fails if a default value (-1) is sent to the
   method
2. SQL Server returns driver specific field information which should be
   used instead of the generic PDO data types
3. Field object information is cached to reduce repetitive reads of
   field data information

Fixes ADOdb#251, ADOdb#234
dregad added a commit to dregad/ADOdb that referenced this issue Aug 28, 2016
Follow-up on c4b339cb12b9ccdea54a1ff42aa853d89e97188b. See ADOdb#251, ADOdb#234.
dregad pushed a commit that referenced this issue Aug 31, 2016
1. The fetchfield method fails if a default value (-1) is sent to the
   method
2. SQL Server returns driver specific field information which should be
   used instead of the generic PDO data types
3. Field object information is cached to reduce repetitive reads of
   field data information

Fixes #251, #234
dregad added a commit that referenced this issue Aug 31, 2016
Follow-up on c4b339cb12b9ccdea54a1ff42aa853d89e97188b. See #251, #234.
dregad pushed a commit that referenced this issue Sep 7, 2016
1. The fetchfield method fails if a default value (-1) is sent to the
   method
2. SQL Server returns driver specific field information which should be
   used instead of the generic PDO data types
3. Field object information is cached to reduce repetitive reads of
   field data information

Fixes #251, #234
dregad added a commit that referenced this issue Sep 7, 2016
Follow-up on 092a2c9.
Addresses review comments in PR #249.

Fixes #251, #234.
@dregad dregad closed this as completed Sep 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement mssqlnative Native driver for SQL Server driver (Tier 1) pdo The PHP PDO Driver (Tier 2)
Projects
None yet
Development

No branches or pull requests

3 participants