protected function scanForInsertId(Grid $grid)
 {
     if (!$grid->isLoaded()) {
         $primaryKey = $grid->primaryKey();
         $foundKeyColumn = false;
         if (is_array($primaryKey)) {
             foreach ($primaryKey as $keyColumn) {
                 if (!$keyColumn->isGeneratedOnPublish() || $keyColumn->hasData()) {
                     continue;
                 }
                 $foundKeyColumn = $keyColumn;
                 break;
             }
         } else {
             if ($primaryKey->isGeneratedOnPublish() && !$primaryKey->hasData()) {
                 $foundKeyColumn = $primaryKey;
             }
         }
         if ($foundKeyColumn) {
             $result = $this->query('SELECT SCOPE_IDENTITY() AS [LAST_INSERT_ID]');
             if (!$result || mssql_num_rows($result) != 1) {
                 $this->throwException('Attempt to fetch last insert id value failed: ' . $this->error());
             }
             $dataRow = $this->fetch_row($result);
             $foundKeyColumn->setData(array_shift($dataRow));
         }
     }
 }
 protected function scanForInsertId(Grid $grid)
 {
     if (!$grid->isLoaded()) {
         $primaryKey = $grid->primaryKey();
         $foundKeyColumn = false;
         if (is_array($primaryKey)) {
             foreach ($primaryKey as $keyColumn) {
                 if (!$keyColumn->isGeneratedOnPublish() || $keyColumn->hasData()) {
                     continue;
                 }
                 $foundKeyColumn = $keyColumn;
                 break;
             }
         } else {
             if ($primaryKey->isGeneratedOnPublish() && !$primaryKey->hasData()) {
                 $foundKeyColumn = $primaryKey;
             }
         }
         if ($foundKeyColumn && ($lastInsertId = sqlite_last_insert_rowid($this->getConnection()))) {
             $foundKeyColumn->setData($lastInsertId);
         }
     }
 }
 protected function scanForInsertId(Grid $grid, $sequence, $next = true)
 {
     if (!$grid->isLoaded()) {
         $primaryKey = $grid->primaryKey();
         $foundKeyColumn = false;
         if (is_array($primaryKey)) {
             foreach ($primaryKey as $keyColumn) {
                 if (!$keyColumn->isGeneratedOnPublish() || $keyColumn->hasData()) {
                     continue;
                 }
                 $foundKeyColumn = $keyColumn;
                 break;
             }
         } else {
             if ($primaryKey->isGeneratedOnPublish() && !$primaryKey->hasData()) {
                 $foundKeyColumn = $primaryKey;
             }
         }
         if ($foundKeyColumn) {
             $result = $this->query('SELECT ' . $this->escapeDataName($sequence) . '.' . $this->escapeDataName($next ? 'NEXTVAL' : 'CURRVAL') . ' ' . $this->asColumnOperator . ' ' . $this->escapeDataNameAlias('LAST_INSERT_ID') . ' FROM ' . $this->escapeDataName('DUAL'));
             if (!is_resource($result)) {
                 $this->throwException('Attempt to fetch last insert id value failed: ' . $this->error());
             }
             $dataRow = $this->fetch_row($result);
             $foundKeyColumn->setData(array_shift($dataRow));
         }
     }
 }
 protected function scanForInsertId(Grid $grid)
 {
     if (!$grid->isLoaded()) {
         $primaryKey = $grid->primaryKey();
         $foundKeyColumn = false;
         if (is_array($primaryKey)) {
             foreach ($primaryKey as $keyColumn) {
                 if (!$keyColumn->isGeneratedOnPublish() || $keyColumn->hasData()) {
                     continue;
                 }
                 $foundKeyColumn = $keyColumn;
                 break;
             }
         } else {
             if ($primaryKey instanceof Column && $primaryKey->isGeneratedOnPublish() && !$primaryKey->hasData()) {
                 $foundKeyColumn = $primaryKey;
             }
         }
         if ($foundKeyColumn && in_array($foundKeyColumn->getType(), array(Column::TYPE_FLOAT, Column::TYPE_INTEGER, Column::TYPE_UNSIGNED_INTEGER))) {
             // Executing the query directly, since the mysql_insert_id() command casts the return
             // value to c(long), and may truncate.
             $result = $this->query('SELECT LAST_INSERT_ID()');
             if (!$result || $this->num_rows($result) != 1) {
                 $this->throwException('Attempt to fetch last insert id value failed: ' . $this->error());
             }
             $dataRow = $this->fetch_row($result);
             $foundKeyColumn->setData(array_shift($dataRow));
         }
     }
 }