Doctrine 1
  1. Doctrine 1
  2. DC-439

Import of table with (silly) name "index"

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.1
    • Fix Version/s: 1.2.3
    • Component/s: Import/Export
    • Labels:
      None
    • Environment:
      MS-SQL-Server 2005
      php 5.2.11
      openSUSE 11.1

      Description

      In Doctrine/Import/Mssql.php are this procedure calls:

      92: $sql = 'EXEC sp_primary_keys_rowset @table_name = ' . $this->conn->quoteIdentifier($table, true);
      99: $sql = 'EXEC sp_columns @table_name = ' . $this->conn->quoteIdentifier($table, true);
      219: $query = 'EXEC sp_statistics @table_name = ' . $table;
      222: $query = 'EXEC sp_pkeys @table_name = ' . $table;

      which fail with sql "keyword" table names.

      Using ...['. $table . ' ]' around the table name worked for me.
      I don't know anything about the backend of doctrine.
      Should this be done by quoteIdentifier, or is this fix okay?
      .. @table_name = [' . $this->conn->quoteIdentifier($table, true) . ']';

      Many thanx for all!
      Jochen Bayer

        Activity

        Hide
        Jonathan H. Wage added a comment -

        It is hard to understand what you changed exactly. Can you provide a diff?

        Show
        Jonathan H. Wage added a comment - It is hard to understand what you changed exactly. Can you provide a diff?
        Hide
        Jochen Bayer added a comment -

        Index: Mssql.php
        ===================================================================
        — Mssql.php (Revision 49)
        +++ Mssql.php (Arbeitskopie)
        @@ -89,14 +89,14 @@
        */
        public function listTableColumns($table)
        {

        • $sql = 'EXEC sp_primary_keys_rowset @table_name = ' . $this->conn->quoteIdentifier($table, true);
          + $sql = 'EXEC sp_primary_keys_rowset @table_name = [' . $this->conn->quoteIdentifier($table, true) . ']';
          $result = $this->conn->fetchAssoc($sql);
          $primary = array();
          foreach ($result as $key => $val) { $primary[] = $val['COLUMN_NAME']; }
        • $sql = 'EXEC sp_columns @table_name = ' . $this->conn->quoteIdentifier($table, true);
          + $sql = 'EXEC sp_columns @table_name = [' . $this->conn->quoteIdentifier($table, true) . ']';
          $result = $this->conn->fetchAssoc($sql);
          $columns = array();

        @@ -216,10 +216,10 @@
        }
        }
        $table = $this->conn->quote($table, 'text');

        • $query = 'EXEC sp_statistics @table_name = ' . $table;
          + $query = 'EXEC sp_statistics @table_name = [' . $table . ']';
          $indexes = $this->conn->fetchColumn($query, $keyName);
        • $query = 'EXEC sp_pkeys @table_name = ' . $table;
          + $query = 'EXEC sp_pkeys @table_name = [' . $table. ']';
          $pkAll = $this->conn->fetchColumn($query, $pkName);

        $result = array();

        Show
        Jochen Bayer added a comment - Index: Mssql.php =================================================================== — Mssql.php (Revision 49) +++ Mssql.php (Arbeitskopie) @@ -89,14 +89,14 @@ */ public function listTableColumns($table) { $sql = 'EXEC sp_primary_keys_rowset @table_name = ' . $this->conn->quoteIdentifier($table, true); + $sql = 'EXEC sp_primary_keys_rowset @table_name = [' . $this->conn->quoteIdentifier($table, true) . '] '; $result = $this->conn->fetchAssoc($sql); $primary = array(); foreach ($result as $key => $val) { $primary[] = $val['COLUMN_NAME']; } $sql = 'EXEC sp_columns @table_name = ' . $this->conn->quoteIdentifier($table, true); + $sql = 'EXEC sp_columns @table_name = [' . $this->conn->quoteIdentifier($table, true) . '] '; $result = $this->conn->fetchAssoc($sql); $columns = array(); @@ -216,10 +216,10 @@ } } $table = $this->conn->quote($table, 'text'); $query = 'EXEC sp_statistics @table_name = ' . $table; + $query = 'EXEC sp_statistics @table_name = [' . $table . '] '; $indexes = $this->conn->fetchColumn($query, $keyName); $query = 'EXEC sp_pkeys @table_name = ' . $table; + $query = 'EXEC sp_pkeys @table_name = [' . $table. '] '; $pkAll = $this->conn->fetchColumn($query, $pkName); $result = array();
        Hide
        Jonathan H. Wage added a comment -

        You need to turn on identifier quoting. The quoteIdentifier() method takes care of this for you.

        http://www.doctrine-project.org/documentation/manual/1_2/en/configuration:identifier-quoting

        Show
        Jonathan H. Wage added a comment - You need to turn on identifier quoting. The quoteIdentifier() method takes care of this for you. http://www.doctrine-project.org/documentation/manual/1_2/en/configuration:identifier-quoting
        Hide
        Jonathan H. Wage added a comment -

        Fixed missed calls to quoteIdentifier(). Turn on identifier quoting for identifiers to be wrapped with []

        http://www.doctrine-project.org/documentation/manual/1_2/en/configuration:identifier-quoting

        Show
        Jonathan H. Wage added a comment - Fixed missed calls to quoteIdentifier(). Turn on identifier quoting for identifiers to be wrapped with [] http://www.doctrine-project.org/documentation/manual/1_2/en/configuration:identifier-quoting
        Hide
        T. B. added a comment -

        I have a similar problem after executing the symfony (1.4.10) build-schema task:

        SQLSTATE[42000]: Syntax error or access violation: 2812 [Microsoft][SQL Server Native Client 10.0][SQL Server]Could not find stored procedure 'sp_primary_keys_rowset'. (SQLExecute[2812] at ext\pdo_odbc\odbc_stmt.c:254). Failing Query: "EXEC sp_primary_keys_rowset @table_name = Appointment"

        I hoped ATTR_QUOTE_IDENTIFIER will also solve my problem but I get the sama error message:

        SQLSTATE[42000]: Syntax error or access violation: 2812 [Microsoft][SQL Server Native Client 10.0][SQL Server]Could not find stored procedure 'sp_primary_keys_rowset'. (SQLExecute[2812] at ext\pdo_odbc\odbc_stmt.c:254). Failing Query: "EXEC sp_primary_keys_rowset @table_name = [Appointment]"

        Show
        T. B. added a comment - I have a similar problem after executing the symfony (1.4.10) build-schema task: SQLSTATE [42000] : Syntax error or access violation: 2812 [Microsoft] [SQL Server Native Client 10.0] [SQL Server] Could not find stored procedure 'sp_primary_keys_rowset'. (SQLExecute [2812] at ext\pdo_odbc\odbc_stmt.c:254). Failing Query: "EXEC sp_primary_keys_rowset @table_name = Appointment" I hoped ATTR_QUOTE_IDENTIFIER will also solve my problem but I get the sama error message: SQLSTATE [42000] : Syntax error or access violation: 2812 [Microsoft] [SQL Server Native Client 10.0] [SQL Server] Could not find stored procedure 'sp_primary_keys_rowset'. (SQLExecute [2812] at ext\pdo_odbc\odbc_stmt.c:254). Failing Query: "EXEC sp_primary_keys_rowset @table_name = [Appointment] "

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Jochen Bayer
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: