Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Schema in SQLSRV not working
#4

(02-06-2021, 07:32 PM)Hrodriguez18 Wrote: #########################################################################################################



I have found a solution for now, it works for me in the same way I will try to make a pull request to improve this situation.



system/Database/SQLSRV/Builder.php:197  


PHP Code:
private function getFullName(string $table): string
 
{
 
    $table_exploded explode('.'$table);
 
    if(count($table_exploded) === 2)
        {
            $this->db->schema str_replace('"'''$table_exploded[0]);
            $tableName $table_exploded[1];
        }else
        {
            $tableName $table;
        }

 if (
$this->db->escapeChar === '"')
 {
 return 
'"' $this->db->getDatabase() . '"."' $this->db->schema '"."' str_replace('"'''$tableName) . '"';
 }
 return 
'[' $this->db->getDatabase() . '].[' $this->db->schema '].[' str_replace('"'''$tableName) . ']';
 } 


I hope it works for you.

Yes pretty much same with me, except I'm breaking it to 3 segments. My Changes are;

system/Database/SQLSRV/Builder.php
PHP Code:
private function getFullName(string $table): string
{
 list(
$dbase$schema$table) = array_pad(explode('.'$table), -3null);

 $dbase = (is_null($dbase)) ? $this->db->getDatabase() : str_replace('"'''$dbase);

 $schema = (is_null($schema)) ? $this->db->schema str_replace('"'''$schema);

 $table =  str_replace('"'''$table);

 if (
$this->db->escapeChar === '"')
 {
  return '"' $dbase '"."' $schema '"."' $table '"';
 }

 return 
'[' $dbase '].[' $schema '].[' $table ']';
 


system/Database/SQLSRV/Connection.php
PHP Code:
protected function _listColumns(string $table ''): string
{
 list(
$dbase$schema$table) = array_pad(explode('.'$table), -3null);

 
$dbase = ($dbase) ?: $this->database;

 
$schema = ($schema) ?: $this->schema;

 return 
'SELECT [COLUMN_NAME] '
  ' FROM [INFORMATION_SCHEMA].[COLUMNS]'
  ' WHERE  [TABLE_NAME] = ' $this->escape($this->DBPrefix $table)
  ' AND [TABLE_SCHEMA] = ' $this->escape($schema);



and

PHP Code:
public function _fieldData(string $table): array
{
 list(
$dbase$schema$table) = array_pad(explode('.'$table), -3null);

 
$dbase = ($dbase) ?: $this->database;

 
$schema = ($schema) ?: $this->schema;

 
$sql 'SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, COLUMN_DEFAULT
  FROM INFORMATION_SCHEMA.COLUMNS
  WHERE TABLE_NAME= ' 
$this->escape(($table)) . ' AND [TABLE_SCHEMA] = ' $this->escape($schema)
  ;

 ...
 ... 

Change this file also if you are using rules. I'm not sure whether we can extend it.
system/Validation/Rules.php

PHP Code:
public function is_not_unique(string $str nullstring $field, array $data): bool
{
 
// Grab any data for exclusion of a single row.
 
list($field$whereField$whereValue) = array_pad(explode(','$field), 3null);

 
$fieldName explode('.'$field);

 
$fieldCount count($fieldName);

 if (
$fieldCount 3)
 {
  // Break the table and field apart
  sscanf($field'%[^.].%[^.].%[^.].%[^.]'$dbase$schema$table$field);

  $table $dbase '.' $schema '.' $table;
 }
 elseif (
$fieldCount 2)
 {
  // Break the table and field apart
  sscanf($field'%[^.].%[^.].%[^.]'$schema$table$field);

  $table $schema '.' $table;
 }
 else
 {
  // Break the table and field apart
  scanf($field'%[^.].%[^.]'$table$field);
 }

  ...
  ... 

and

PHP Code:
public function is_unique(string $str nullstring $field, array $data): bool
{
  // Grab any data for exclusion of a single row.
  list($field$ignoreField$ignoreValue) = array_pad(explode(','$field), 3null);

  $fieldName explode('.'$field);

  $fieldCount count($fieldName);

 if (
$fieldCount 3)
 {
  // Break the table and field apart
  sscanf($field'%[^.].%[^.].%[^.].%[^.]'$dbase$schema$table$field);

  $table $dbase '.' $schema '.' $table;
 }
 elseif (
$fieldCount 2)
 {
  // Break the table and field apart
  sscanf($field'%[^.].%[^.].%[^.]'$schema$table$field);

  $table $schema '.' $table;
 }
 else
 {
  // Break the table and field apart
  scanf($field'%[^.].%[^.]'$table$field);
 }

  ...
  ... 
Reply


Messages In This Thread
RE: Schema in SQLSRV not working - by nfaiz - 02-03-2021, 05:58 AM
RE: Schema in SQLSRV not working - by nfaiz - 02-07-2021, 12:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB