1 頁 (共 1 頁)

tck/odbc

發表於 : 2018-05-28 16:18:57
yehlu
config/app.php

代碼: 選擇全部

TCK\Odbc\OdbcServiceProvider::class,
config/databasde.php

代碼: 選擇全部

        'odbc'   => [
                'driver'   => 'odbc',
                'dsn'      => 'odbc:dbserverdsn',
                'host'     => ,
                'port'     => '1433',
                'database' => '',
                'username' => '',
                'password' =>  '',
                'grammar' => [
                        'query' => Illuminate\Database\Query\Grammars\SqlServerGrammar::class,
                        'schema' => Illuminate\Database\Schema\Grammars\SqlServerGrammar::class,
                ],
        ],
/etc/odbcinst.ini

代碼: 選擇全部

[ODBC]
Trace = No
TraceFile = /tmp/odbc.log

[FreeTDS]
Description = FreeTDS
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
UsageCount = 1
/etc/odbc.ini

代碼: 選擇全部

[dbserverdsn]
Driver = FreeTDS
Server = IP
Port = 1433
Database = DBNAME
#Driver=/usr/local/lib/libtdsodbc.so
Driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
UsageCount = 1

[Default]
#Driver=/usr/local/lib/libtdsodbc.so
Driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
/etc/freetds/freetds.conf

代碼: 選擇全部

#   $Id: freetds.conf,v 1.12 2007/12/25 06:02:36 jklowden Exp $
#
# This file is installed by FreeTDS if no file by the same
# name is found in the installation directory.
#
# For information about the layout of this file and its settings,
# see the freetds.conf manpage "man freetds.conf".

# Global settings are overridden by those in a database
# server specific section
[global]
        # TDS protocol version
	tds version = 4.2
	port = 1433

	# Whether to write a TDSDUMP file for diagnostic purposes
	# (setting this to /tmp is insecure on a multi-user system)
;	dump file = /tmp/freetds.log
;	debug flags = 0xffff

	# Command and connection timeouts
;	timeout = 10
;	connect timeout = 10

	# If you get out-of-memory errors, it may mean that your client
	# is trying to allocate a huge buffer for a TEXT field.
	# Try setting 'text size' to a more reasonable limit
	text size = 64512

# A typical Sybase server
[egServer50]
	host = symachine.domain.com
	port = 5000
	tds version = 5.0

# A typical Microsoft server
[egServer70]
	host = ntmachine.domain.com
	port = 1433
	tds version = 7.0

[dbserverdsn]
  database = DBNAME
  host = IP
  port = 1433
  tds version = 7.2
  client charset = UTF-8

Re: tck/odbc fo windows

發表於 : 2018-05-28 17:38:56
yehlu
config/database.php

代碼: 選擇全部

            'odbc' => [
              'driver'   => 'odbc',
              'dsn'      => 'odbc:dbserverdsn',
              'host' => '',
              'database' => '',
              'username' => '',
              'password' => '',
              'prefix' => '',
              'grammar' => [
              		'query' => Illuminate\Database\Query\Grammars\SqlServerGrammar::class,
              		'schema' => Illuminate\Database\Schema\Grammars\SqlServerGrammar::class,
              	],              
                ],
64 位元 ODBC 位置:C:\Windows\System32\odbcad32.exe
32 位元 ODBC 位置:C:\Windows\SysWOW64\odbcad32.exe

Re: tck/odbc SQL 2000

發表於 : 2018-05-29 08:56:21
yehlu
ODBCSchemaGrammar.php

代碼: 選擇全部

        public function compileColumnExists($table)
        {
return "select COLUMN_NAME
from SUNRISECT.information_schema.columns
where TABLE_NAME = '$table'
order by table_name, ordinal_position";
        }

ODBCQueryGrammar.php

代碼: 選擇全部

<?php namespace TCK\Odbc;

use Illuminate\Support\Fluent;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Grammars\Grammar;

class ODBCSchemaGrammar extends Grammar {

	/**
	 * The keyword identifier wrapper format.
	 *
	 * @var string
	 */
	protected $wrapper = '%s';

	/**
	 * The possible column modifiers.
	 *
	 * @var array
	 */
	protected $modifiers = array( 'Unsigned', 'Nullable', 'Default', 'Increment' );

	/**
	 * Compile the query to determine if a table exists.
	 *
	 * @return string
	 */
	public function compileTableExists()
	{
		return 'select * from information_schema.tables where table_schema = ? and table_name = ?';
	}

	/**
	 * Compile a create table command.
	 *
	 * @param  Illuminate\Database\Schema\Blueprint $blueprint
	 * @param  Illuminate\Support\Fluent            $command
	 *
	 * @return string
	 */
	public function compileCreate( Blueprint $blueprint, Fluent $command )
	{
		$columns = implode( ', ', $this->getColumns( $blueprint ) );

		return 'create table ' . $this->wrapTable( $blueprint ) . " ($columns)";
	}

	/**
	 * Compile a create table command.
	 *
	 * @param  Illuminate\Database\Schema\Blueprint $blueprint
	 * @param  Illuminate\Support\Fluent            $command
	 *
	 * @return string
	 */
	public function compileAdd( Blueprint $blueprint, Fluent $command )
	{
		$table = $this->wrapTable( $blueprint );

		$columns = $this->prefixArray( 'add', $this->getColumns( $blueprint ) );

		return 'alter table ' . $table . ' ' . implode( ', ', $columns );
	}

	/**
	 * Compile a primary key command.
	 *
	 * @param  Illuminate\Database\Schema\Blueprint $blueprint
	 * @param  Illuminate\Support\Fluent            $command
	 *
	 * @return string
	 */
	public function compilePrimary( Blueprint $blueprint, Fluent $command )
	{
		$command->name( null );

		return $this->compileKey( $blueprint, $command, 'primary key' );
	}

	/**
	 * Compile an index creation command.
	 *
	 * @param  Illuminate\Database\Schema\Blueprint $blueprint
	 * @param  Illuminate\Support\Fluent            $command
	 * @param  string                               $type
	 *
	 * @return string
	 */
	protected function compileKey( Blueprint $blueprint, Fluent $command, $type )
	{
		$columns = $this->columnize( $command->columns );

		$table = $this->wrapTable( $blueprint );

		return "alter table {$table} add {$type} {$command->index}($columns)";
	}

	/**
	 * Compile a unique key command.
	 *
	 * @param  Illuminate\Database\Schema\Blueprint $blueprint
	 * @param  Illuminate\Support\Fluent            $command
	 *
	 * @return string
	 */
	public function compileUnique( Blueprint $blueprint, Fluent $command )
	{
		return $this->compileKey( $blueprint, $command, 'unique' );
	}

	/**
	 * Compile a plain index key command.
	 *
	 * @param  Illuminate\Database\Schema\Blueprint $blueprint
	 * @param  Illuminate\Support\Fluent            $command
	 *
	 * @return string
	 */
	public function compileIndex( Blueprint $blueprint, Fluent $command )
	{
		return $this->compileKey( $blueprint, $command, 'index' );
	}

	/**
	 * Compile a drop table command.
	 *
	 * @param  Illuminate\Database\Schema\Blueprint $blueprint
	 * @param  Illuminate\Support\Fluent            $command
	 *
	 * @return string
	 */
	public function compileDrop( Blueprint $blueprint, Fluent $command )
	{
		return 'drop table ' . $this->wrapTable( $blueprint );
	}

	/**
	 * Compile a drop table (if exists) command.
	 *
	 * @param  Illuminate\Database\Schema\Blueprint $blueprint
	 * @param  Illuminate\Support\Fluent            $command
	 *
	 * @return string
	 */
	public function compileDropIfExists( Blueprint $blueprint, Fluent $command )
	{
		return 'drop table if exists ' . $this->wrapTable( $blueprint );
	}

	/**
	 * Compile a drop column command.
	 *
	 * @param  Illuminate\Database\Schema\Blueprint $blueprint
	 * @param  Illuminate\Support\Fluent            $command
	 *
	 * @return string
	 */
	public function compileDropColumn( Blueprint $blueprint, Fluent $command )
	{
		$columns = $this->prefixArray( 'drop', $this->wrapArray( $command->columns ) );

		$table = $this->wrapTable( $blueprint );

		return 'alter table ' . $table . ' ' . implode( ', ', $columns );
	}

	/**
	 * Compile a drop primary key command.
	 *
	 * @param  Illuminate\Database\Schema\Blueprint $blueprint
	 * @param  Illuminate\Support\Fluent            $command
	 *
	 * @return string
	 */
	public function compileDropPrimary( Blueprint $blueprint, Fluent $command )
	{
		return 'alter table ' . $this->wrapTable( $blueprint ) . ' drop primary key';
	}

	/**
	 * Compile a drop unique key command.
	 *
	 * @param  Illuminate\Database\Schema\Blueprint $blueprint
	 * @param  Illuminate\Support\Fluent            $command
	 *
	 * @return string
	 */
	public function compileDropUnique( Blueprint $blueprint, Fluent $command )
	{
		$table = $this->wrapTable( $blueprint );

		return "alter table {$table} drop index {$command->index}";
	}

	/**
	 * Compile a drop index command.
	 *
	 * @param  Illuminate\Database\Schema\Blueprint $blueprint
	 * @param  Illuminate\Support\Fluent            $command
	 *
	 * @return string
	 */
	public function compileDropIndex( Blueprint $blueprint, Fluent $command )
	{
		$table = $this->wrapTable( $blueprint );

		return "alter table {$table} drop index {$command->index}";
	}

	/**
	 * Compile a drop foreign key command.
	 *
	 * @param  Illuminate\Database\Schema\Blueprint $blueprint
	 * @param  Illuminate\Support\Fluent            $command
	 *
	 * @return string
	 */
	public function compileDropForeign( Blueprint $blueprint, Fluent $command )
	{
		$table = $this->wrapTable( $blueprint );

		return "alter table {$table} drop foreign key {$command->index}";
	}

	/**
	 * Compile a rename table command.
	 *
	 * @param  Illuminate\Database\Schema\Blueprint $blueprint
	 * @param  Illuminate\Support\Fluent            $command
	 *
	 * @return string
	 */
	public function compileRename( Blueprint $blueprint, Fluent $command )
	{
		$from = $this->wrapTable( $blueprint );

		return "rename table {$from} to " . $this->wrapTable( $command->to );
	}

	/**
	 * Create the column definition for a string type.
	 *
	 * @param  Illuminate\Support\Fluent $column
	 *
	 * @return string
	 */
	protected function typeString( Fluent $column )
	{
		return "varchar({$column->length})";
	}

	/**
	 * Create the column definition for a text type.
	 *
	 * @param  Illuminate\Support\Fluent $column
	 *
	 * @return string
	 */
	protected function typeText( Fluent $column )
	{
		return 'text';
	}

	/**
	 * Create the column definition for a integer type.
	 *
	 * @param  Illuminate\Support\Fluent $column
	 *
	 * @return string
	 */
	protected function typeInteger( Fluent $column )
	{
		return 'int';
	}

	/**
	 * Create the column definition for a float type.
	 *
	 * @param  Illuminate\Support\Fluent $column
	 *
	 * @return string
	 */
	protected function typeFloat( Fluent $column )
	{
		return "float({$column->total}, {$column->places})";
	}

	/**
	 * Create the column definition for a decimal type.
	 *
	 * @param  Illuminate\Support\Fluent $column
	 *
	 * @return string
	 */
	protected function typeDecimal( Fluent $column )
	{
		return "decimal({$column->total}, {$column->places})";
	}

	/**
	 * Create the column definition for a boolean type.
	 *
	 * @param  Illuminate\Support\Fluent $column
	 *
	 * @return string
	 */
	protected function typeBoolean( Fluent $column )
	{
		return 'tinyint';
	}

	/**
	 * Create the column definition for a enum type.
	 *
	 * @param  Illuminate\Support\Fluent $column
	 *
	 * @return string
	 */
	protected function typeEnum( Fluent $column )
	{
		return "enum('" . implode( "', '", $column->allowed ) . "')";
	}

	/**
	 * Create the column definition for a date type.
	 *
	 * @param  Illuminate\Support\Fluent $column
	 *
	 * @return string
	 */
	protected function typeDate( Fluent $column )
	{
		return 'date';
	}

	/**
	 * Create the column definition for a date-time type.
	 *
	 * @param  Illuminate\Support\Fluent $column
	 *
	 * @return string
	 */
	protected function typeDateTime( Fluent $column )
	{
		return 'datetime';
	}

	/**
	 * Create the column definition for a time type.
	 *
	 * @param  Illuminate\Support\Fluent $column
	 *
	 * @return string
	 */
	protected function typeTime( Fluent $column )
	{
		return 'time';
	}

	/**
	 * Create the column definition for a timestamp type.
	 *
	 * @param  Illuminate\Support\Fluent $column
	 *
	 * @return string
	 */
	protected function typeTimestamp( Fluent $column )
	{
		return 'timestamp default 0';
	}

	/**
	 * Create the column definition for a binary type.
	 *
	 * @param  Illuminate\Support\Fluent $column
	 *
	 * @return string
	 */
	protected function typeBinary( Fluent $column )
	{
		return 'blob';
	}

	/**
	 * Get the SQL for an unsigned column modifier.
	 *
	 * @param  Illuminate\Database\Schema\Blueprint $blueprint
	 * @param  Illuminate\Support\Fluent            $column
	 *
	 * @return string|null
	 */
	protected function modifyUnsigned( Blueprint $blueprint, Fluent $column )
	{
		if ( $column->type == 'integer' and $column->unsigned )
		{
			return ' unsigned';
		}
	}

	/**
	 * Get the SQL for a nullable column modifier.
	 *
	 * @param  Illuminate\Database\Schema\Blueprint $blueprint
	 * @param  Illuminate\Support\Fluent            $column
	 *
	 * @return string|null
	 */
	protected function modifyNullable( Blueprint $blueprint, Fluent $column )
	{
		return $column->nullable ? ' null' : ' not null';
	}

	/**
	 * Get the SQL for a default column modifier.
	 *
	 * @param  Illuminate\Database\Schema\Blueprint $blueprint
	 * @param  Illuminate\Support\Fluent            $column
	 *
	 * @return string|null
	 */
	protected function modifyDefault( Blueprint $blueprint, Fluent $column )
	{
		if ( ! is_null( $column->default ) )
		{
			return " default '" . $this->getDefaultValue( $column->default ) . "'";
		}
	}

	/**
	 * Get the SQL for an auto-increment column modifier.
	 *
	 * @param  Illuminate\Database\Schema\Blueprint $blueprint
	 * @param  Illuminate\Support\Fluent            $column
	 *
	 * @return string|null
	 */
	protected function modifyIncrement( Blueprint $blueprint, Fluent $column )
	{
		if ( $column->type == 'integer' and $column->autoIncrement )
		{
			return ' auto_increment primary key';
		}
	}

	public function compileColumnExists($table)
	{
/*
			return "select col.name from sys.columns as col
							join sys.objects as obj on col.object_id = obj.object_id
							where obj.type = 'U' and obj.name = '$table'";
*/
return "select COLUMN_NAME
from SUNRISECT.information_schema.columns
where TABLE_NAME = '$table'
order by table_name, ordinal_position";
	}

}