Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Usar o Framework com sql server Olá pessoal! Para conseguir trabalhar com sql server foi necessário alterar duas classes: 1º - TConnection: a extensão mssql já não funciona há muito tempo. A microsoft desenvolveu uma extensão para conexão com php e continua dando manutenção. Basta instalar e fazer o php reconhecê-la. A mudança será feita na linha 73 e a string ficará da seguinte forma:...
ES
Usar o Framework com sql server  
Fechado
Olá pessoal!

Para conseguir trabalhar com sql server foi necessário alterar duas classes:

1º - TConnection: a extensão mssql já não funciona há muito tempo. A microsoft desenvolveu uma extensão para conexão com php e continua dando manutenção. Basta instalar e fazer o php reconhecê-la.
A mudança será feita na linha 73 e a string ficará da seguinte forma:
  1. <?php $conn = new PDO("sqlsrv:Server={$host};Database={$name}"$user$pass); ?>


2º - TSqlSelect: linha 33 passa a ter a seguinte sintaxe:
  1. <?php if (($driver == 'sqlsrv') or ($driver == 'dblib')) ?>

Caso alguém tenha enfrentado esse problema espero que essas informações ajude.
Só lamento o Adianti Studio ainda não comportar o driver para sql server. Estou aguardando Pablo.

abs
Eliezer

Pacotão Dominando o Adianti Framework 7
O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4


Dominando o Adianti 7 Quero me inscrever agora!

Comentários (9)


ES

Olá Pablo,
Depois de conseguir conexão com o banco de dados fiz uma listagem para teste e eis que começaram os primeiros problemas.

A listagem foi preenchida perfeitamente mas apareceu a tela de mensagem com o seguinte erro:
Error SQLSTATE[42000]: [Microsoft][SQL Server Native Client 10.0][SQL Server]Nenhum nome de coluna especificado para a coluna 1 de 'TAB'.

Tentei várias coisas mas nada deu certo.
Abaixo coloco os códigos das classes model e control:

Model
  1. <?php /**
  2.  * EstoqueProd Active Record
  3.  * @author  EliezerM
  4.  */
  5. class EstoqueProd extends TRecord
  6. {
  7.     const TABLENAME 'ESTOQUE_PRODUTOS';
  8.     const PRIMARYKEY'PRODUTO';
  9.     const IDPOLICY =  'serial'// {max, serial} 
  10.     
  11.     /**
  12.      * Constructor method
  13.      */
  14.     public function __construct($id NULL)
  15.     {
  16.         parent::__construct($id);
  17.         parent::addAttribute('PRODUTO');
  18.         parent::addAttribute('COR_PRODUTO');
  19.         parent::addAttribute('FILIAL');
  20.         parent::addAttribute('ESTOQUE');
  21.     }
  22.    
  23. ?>


Control
  1. <?php
  2. /**
  3.  * Bens_moveisList Listing
  4.  * @author  <your name here>
  5.  */
  6. class ProdutosEstLis extends TPage
  7. {
  8.     private $form;     // registration form
  9.     private $datagrid// listing
  10.     private $pageNavigation;
  11.     private $loaded;
  12.     
  13.     /**
  14.      * Class constructor
  15.      * Creates the page, the form and the listing
  16.      */
  17.     public function __construct()
  18.     {
  19.         parent::__construct();
  20.         
  21.         // creates the form
  22.         $this->form = new TForm('form_search_Est_Prod');
  23.         
  24.         // creates a table
  25.         $table = new TTable;
  26.         
  27.         // add the table inside the form
  28.         $this->form->add($table);
  29.         
  30.         // create the form fields
  31.         $filter = new TEntry('PRODUTO');
  32.         $filter->setValue(TSession::getValue('EstoqueProd_PRODUTO'));
  33.         
  34.         // add a row for the filter field
  35.         $row=$table->addRow();
  36.         $row->addCell(new TLabel('Produto:'));
  37.         $row->addCell($filter);
  38.         
  39.         // create two action buttons to the form
  40.         $find_button = new TButton('find');
  41.         $new_button  = new TButton('new');
  42.         // define the button actions
  43.         $find_button->setAction(new TAction(array($this'onSearch')), _t('Find'));
  44.         $find_button->setImage('ico_find.png');
  45.         
  46.         $new_button->setAction(new TAction(array('EstoqueProdForm''onEdit')), _t('New'));
  47.         $new_button->setImage('ico_new.png');
  48.         
  49.         // add a row for the form actions
  50.         $row=$table->addRow();
  51.         $row->addCell($find_button);
  52.         $row->addCell($new_button);
  53.         
  54.         // define wich are the form fields
  55.         $this->form->setFields(array($filter$find_button$new_button));
  56.         
  57.         // creates a DataGrid
  58.         $this->datagrid = new TDataGrid;
  59.         $this->datagrid->setHeight(320);
  60.         
  61.         // creates the datagrid columns
  62.         $id   = new TDataGridColumn('PRODUTO''Produto''center'100);
  63.         $patrimonio   = new TDataGridColumn('COR_PRODUTO''Cor''center'30);
  64.         $desc_pat   = new TDataGridColumn('FILIAL''Filial''left'180);
  65.         $item   = new TDataGridColumn('ESTOQUE''Qtde''right'50);
  66.         // add the columns to the DataGrid
  67.         $this->datagrid->addColumn($id);
  68.         $this->datagrid->addColumn($patrimonio);
  69.         $this->datagrid->addColumn($desc_pat);
  70.         $this->datagrid->addColumn($item);
  71.         // creates the datagrid actions
  72.         $order2= new TAction(array($this'onReload'));
  73.         $order3= new TAction(array($this'onReload'));
  74.         $order4= new TAction(array($this'onReload'));
  75.         // define the ordering parameters
  76.         $order2->setParameter('order''PRODUTO');
  77.         $order3->setParameter('order''COR_PRODUTO');
  78.         $order4->setParameter('order''FILIAL');
  79.         // assign the ordering actions
  80.         $patrimonio->setAction($order2);
  81.         $desc_pat->setAction($order3);
  82.         $item->setAction($order4);
  83.         
  84.         // creates two datagrid actions
  85.         $action1 = new TDataGridAction(array('EstoqueProdForm''onEdit'));
  86.         $action1->setLabel(_t('Edit'));
  87.         $action1->setImage('ico_edit.png');
  88.         $action1->setField('id');
  89.         
  90.         $action2 = new TDataGridAction(array($this'onDelete'));
  91.         $action2->setLabel(_t('Delete'));
  92.         $action2->setImage('ico_delete.png');
  93.         $action2->setField('id');
  94.         
  95.         // add the actions to the datagrid
  96.         $this->datagrid->addAction($action1);
  97.         $this->datagrid->addAction($action2);
  98.         
  99.         // create the datagrid model
  100.         $this->datagrid->createModel();
  101.         
  102.         // creates the page navigation
  103.         $this->pageNavigation = new TPageNavigation;
  104.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  105.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  106.         
  107.         // creates the page structure using a table
  108.         $table = new TTable;
  109.         // add a row to the form
  110.         $row $table->addRow();
  111.         $row->addCell($this->form);
  112.         // add a row to the datagrid
  113.         $row $table->addRow();
  114.         $row->addCell($this->datagrid);
  115.         // add a row for page navigation
  116.         $row $table->addRow();
  117.         $row->addCell($this->pageNavigation);
  118.         // add the table inside the page
  119.         parent::add($table);
  120.     }
  121.     
  122.     /**
  123.      * method onSearch()
  124.      * Register the filter in the session when the user performs a search
  125.      */
  126.     function onSearch()
  127.     {
  128.         // get the search form data
  129.         $data $this->form->getData();
  130.         
  131.         TSession::setValue('EstoqueProd_filter',   NULL);
  132.         TSession::setValue('EstoqueProd_PRODUTO''');
  133.         
  134.         // check if the user has filled the form
  135.         if (isset($data->patrimonio))
  136.         {
  137.             // creates a filter using what the user has typed
  138.             $filter = new TFilter('PRODUTO''like'"%{$data->patrimonio}%");
  139.             
  140.             // stores the filter in the session
  141.             TSession::setValue('EstoqueProd_filter',   $filter);
  142.             TSession::setValue('EstoqueProd_PRODUTO'$data->patrimonio);
  143.             
  144.             // fill the form with data again
  145.             $this->form->setData($data);
  146.         }
  147.         
  148.         $param=array();
  149.         $param['offset']    =0;
  150.         $param['first_page']=1;
  151.         $this->onReload($param);
  152.     }
  153.     
  154.     /**
  155.      * method onReload()
  156.      * Load the datagrid with the database objects
  157.      */
  158.     function onReload($param NULL)
  159.     {
  160.         try
  161.         {
  162.             // open a transaction with database 'con_mysql'
  163.             TTransaction::open('con_mssql');
  164.             
  165.             // creates a repository for Bens_moveis
  166.             $repository = new TRepository('EstoqueProd');
  167.             $limit 10;
  168.             // creates a criteria
  169.             $criteria = new TCriteria;
  170.             $criteria->setProperties($param); // order, offset
  171.             $criteria->setProperty('limit'$limit);
  172.             
  173.             if (TSession::getValue('EstoqueProd_filter'))
  174.             {
  175.                 // add the filter stored in the session to the criteria
  176.                 $criteria->add(TSession::getValue('EstoqueProd_filter'));
  177.             }
  178.             
  179.             // load the objects according to criteria
  180.             $objects $repository->load($criteria);
  181.             
  182.             $this->datagrid->clear();
  183.             if ($objects)
  184.             {
  185.                 // iterate the collection of active records
  186.                 foreach ($objects as $object)
  187.                 {
  188.                     //altera o valor para iso-8859-1
  189.                     $object->FILIAL iconv('utf-8','iso-8859-1'$object->FILIAL);
  190.                     // add the object inside the datagrid
  191.                     $this->datagrid->addItem($object);
  192.                 }
  193.             }
  194.             
  195.             // reset the criteria for record count
  196.             $criteria->resetProperties();
  197.             $count$repository->count($criteria);
  198.             
  199.             $this->pageNavigation->setCount($count); // count of records
  200.             $this->pageNavigation->setProperties($param); // order, page
  201.             $this->pageNavigation->setLimit($limit); // limit
  202.             
  203.             // close the transaction
  204.             TTransaction::close();
  205.             $this->loaded true;
  206.         }
  207.         catch (Exception $e// in case of exception
  208.         {
  209.             // shows the exception error message
  210.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  211.             
  212.             // undo all pending operations
  213.             TTransaction::rollback();
  214.         }
  215.     }
  216.     
  217.     /**
  218.      * method onDelete()
  219.      * executed whenever the user clicks at the delete button
  220.      * Ask if the user really wants to delete the record
  221.      */
  222.     function onDelete($param)
  223.     {
  224.         // get the parameter $key
  225.         $key=$param['key'];
  226.         
  227.         // define two actions
  228.         $action = new TAction(array($this'Delete'));
  229.         
  230.         // define the action parameters
  231.         $action->setParameter('key'$key);
  232.         
  233.         // shows a dialog to the user
  234.         new TQuestion(TAdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  235.     }
  236.     
  237.     /**
  238.      * method Delete()
  239.      * Delete a record
  240.      */
  241.     function Delete($param)
  242.     {
  243.         try
  244.         {
  245.             // get the parameter $key
  246.             $key=$param['key'];
  247.             // open a transaction with database 'con_mysql'
  248.             TTransaction::open('con_mssql');
  249.             
  250.             // instantiates object Bens_moveis
  251.             $object = new EstoqueProd($key);
  252.             
  253.             // deletes the object from the database
  254.             $object->delete();
  255.             
  256.             // close the transaction
  257.             TTransaction::close();
  258.             
  259.             // reload the listing
  260.             $this->onReload();
  261.             // shows the success message
  262.             new TMessage('info'TAdiantiCoreTranslator::translate('Record deleted'));
  263.         }
  264.         catch (Exception $e// in case of exception
  265.         {
  266.             // shows the exception error message
  267.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  268.             
  269.             // undo all pending operations
  270.             TTransaction::rollback();
  271.         }
  272.     }
  273.     
  274.     /**
  275.      * method show()
  276.      * Shows the page
  277.      */
  278.     function show()
  279.     {
  280.         // check if the datagrid is already loaded
  281.         if (!$this->loaded)
  282.         {
  283.             $this->onReload();
  284.         }
  285.         parent::show();
  286.     }
  287. }
  288. ?>


Se tiver alguma idéia agradeço.

abs

Eliezer</your>
PD

Oi Eliezer,

Você poderia mandar registrar os LOGS, e depois executar os SQL diretamente no SQL Server para ver qual Instrução SQL foi montada com erro:

www.adianti.com.br/doc-framework-Persistence-Objects-RegisterLog

um abraço,
Pablo
ES

Pablo,
veja o que o log registrou e sinceramente não estou entendendo a instrução.

2013-02-03 08:41:31 :: ** SELECIONANDO ESTOQUE

2013-02-03 08:41:31 :: SELECT * FROM ( SELECT TOP 10 * FROM ( SELECT TOP 10 * FROM ESTOQUE_PRODUTOS WHERE (PRODUTO like '%%') ORDER BY 1 ASC) AS TAB ORDER BY 1 DESC) AS TAB2 ORDER BY PRODUTO

2013-02-03 08:41:31 :: SELECT count(*) FROM ( SELECT TOP 0 count(*) FROM ( SELECT TOP 0 count(*) FROM ESTOQUE_PRODUTOS WHERE (PRODUTO like '%%') ORDER BY 1 ASC) AS TAB ORDER BY 1 DESC) AS TAB2


Se puder me ajudar agradeço

abs
Eliezer
ES

Olá Pablo
É com enorme satisfação que informo a todos os interessados que consegui resolver os erros apresentados na paginação SQL Server e coloco a solução abaixo.
Pablo, se você puder testar, melhorar e homologar para a próxima versão ficarei imensamente grato. Segue:

Alteração da Classe TSqlSelect método getInstructionSqlServer() a partir da linha 117, o código ficará assim:
  1. <?php
  2. if (isset($limit) and $limit != NULL and (!isset($offset) or $offset == NULL))
  3.         {
  4.             $this->sql  " SELECT TOP {$limit} " implode(','$this->columns) . " FROM {$this->entity} {$sql_where} {$sql_order}";
  5.         }
  6.         else if (isset($limit) and isset($offset) and $limit != NULL and $offset != NULL)
  7.         {
  8.             // monsta a instrução de SELECT
  9.             $this->sql  "SELECT TOP {$limit} * FROM (SELECT ROW_NUMBER() OVER ({$sql_order}) AS TAB, *
  10.                             FROM " $this->entity {$sql_where}) AS TAB2
  11.                             WHERE TAB > (({$offset} - 1) * {$limit})";
  12.         }
  13. ?>


PS.: O SQL que trabalho é o 2008 e portanto não testei esse código nessa versão.

abs

Eliezer

ES

Desculpe a falta de informação mas eu não testei o código no SQL 2012, só testei no 2008

att.
Eliezer
PD

Só pra ficar registrado aqui. A próxima versão do framework virá com suporte nativo à Sql Server e Oracle.

abs,
Pablo
ES

Gostei D+ dessa notícia!!!!

Muito obrigado!

abs,
Eliezer
VC

Pablo, perdão por postar em um post tão antigo, mas vi a interação do Eliezer e me chamou a atenção.... Estou testando o Studio e ao tentar criar as tabelas básicas do Template 3 ocorreu um erro na criação da System_User, não sei se o SQL vai permitir esta criação, poderia por favor me orientar se preciso mudar algo para aceitar? Meu SQL é o 2014 e fica na KingHost.

Abraços

Valdir
CL

Olá pessoal, o erro

42000 continua com o SQL Server no Studio 5.6 ?