Trocar Boolean por Char(1) no Firebird 2.5.2

Delphi

24/04/2013

Pessoal, como todos sabem, Firebird não tem BOOLEAN, TRUE ou FALSE. Estou trocando numa unit TRUE ou FALSE pro S ou N e estou tendo dificuldades. O banco foi feito em INTERBASE 7.5 usando BOOLEAN e converti para FIREBIRD 2.5.2 usando CHAR(1).

Acho que nessa unit teria que trocar onde é TRUE, por S e FALSE por N

Esse trecho de código tem haver:
+ QuotedStr ('N');
.AsString := ‘N’; 


Segue unit:

unit untFrmPermissoesUsuarios;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ExtCtrls, DBCtrls, StdCtrls, Buttons, DB;

type
  TFrmPermissoesUsuarios = class(TForm)
    Label1: TLabel;
    dbUsuarios: TDBLookupComboBox;
    Panel1: TPanel;
    Label2: TLabel;
    btnFechar: TBitBtn;
    cbConsultar: TCheckBox;
    cbIncluir: TCheckBox;
    cbExcluir: TCheckBox;
    cbAlterar: TCheckBox;
    btnSalvar: TBitBtn;
    dsLookupUsuarios: TDataSource;
    tvMenus: TTreeView;
    procedure btnFecharClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure dbUsuariosKeyPress(Sender: TObject; var Key: Char);
    procedure dbUsuariosCloseUp(Sender: TObject);
    procedure btnSalvarClick(Sender: TObject);
    procedure tvMenusClick(Sender: TObject);
  private
    semDireitosTela : Boolean;
    procedure CarregarMenus;
    procedure LimparLista;
    procedure CarregarDireitosUsuarioMenu(const codUsuario, codMenu: Integer);
    procedure HabilitarOpcoes(const tof : Boolean);
    function retornaNoPai(codPai: Integer): TTreeNode;
    procedure verificarPermissaoMenuPai(const no: TTreeNode);
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmPermissoesUsuarios: TFrmPermissoesUsuarios;

implementation

uses untDMPrincipal, untDMCadastros, SqlExpr;

{$R *.dfm}

procedure TFrmPermissoesUsuarios.btnFecharClick(Sender: TObject);
begin
  Close;
end;

function TFRmPermissoesUsuarios.retornaNoPai(codPai : Integer) : TTreeNode;
var
  i : Integer;
begin
  Result := nil;
  for i := 0 to Pred(tvMenus.Items.Count) do
    if Integer(tvMenus.Items[i].Data) = codPai then
    begin
      Result := tvMenus.Items[i];
      Exit;
    end;
end;

procedure TFrmPermissoesUsuarios.CarregarMenus;
var
  no : TTreeNode;
begin
  tvMenus.Items.Clear;
  with DMPrincipal.datasetAux do
  begin
    Close;
    CommandText := 'SELECT MEN_CODIGO, MEN_NOME, MEN_CODIGOPAI FROM MENUS ORDER BY MEN_CODIGO';
    Open;
    First;
    while not Eof do
    begin
      if FieldByName('MEN_CODIGOPAI').AsString = '' then
        tvMenus.Items.AddObject(nil, FieldByName('MEN_NOME').AsString, Pointer(FieldByName('MEN_CODIGO').AsInteger))
      else
      begin
        no := retornaNoPai(FieldByName('MEN_CODIGOPAI').AsInteger);
        if Assigned(no) then
          tvMenus.Items.AddChildObject(no, FieldByName('MEN_NOME').AsString, Pointer(FieldByName('MEN_CODIGO').AsInteger));
      end;
      Next;
    end;
  end;
end;

procedure TFrmPermissoesUsuarios.HabilitarOpcoes(const tof : Boolean);
begin
  cbConsultar.Checked := False;
  cbConsultar.Enabled := tof;
  cbIncluir.Checked := False;
  cbIncluir.Enabled := tof;
  cbAlterar.Checked := False;
  cbAlterar.Enabled := tof;
  cbExcluir.Checked := False;
  cbExcluir.Enabled := tof;
end;

procedure TFrmPermissoesUsuarios.FormCreate(Sender: TObject);
begin
  dsLookupUsuarios.DataSet.Open;
  btnSalvar.Enabled := False;
  HabilitarOpcoes(False);
  semDireitosTela := False;
end;

procedure TFrmPermissoesUsuarios.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  dsLookupUsuarios.DataSet.Close;
end;

procedure TFrmPermissoesUsuarios.LimparLista;
begin
  tvMenus.Items.Clear;
end;

procedure TFrmPermissoesUsuarios.dbUsuariosKeyPress(Sender: TObject;
  var Key: Char);
begin
  if Key = #27 then
  begin
    dbUsuarios.KeyValue := -1;
    btnSalvar.Enabled := False;
    HabilitarOpcoes(False);
    LimparLista;
  end;
end;

procedure TFrmPermissoesUsuarios.dbUsuariosCloseUp(Sender: TObject);
begin
  if dbUsuarios.Text <> '' then
    CarregarMenus;
end;

procedure TFrmPermissoesUsuarios.CarregarDireitosUsuarioMenu(const codUsuario, codMenu : Integer);
begin
  with DMPrincipal.datasetAux do
  begin
    Close;
    CommandText := 'SELECT PU_NOVO, PU_ALTERAR, PU_APAGAR, PU_CONSULTAR ' +
                   '  FROM PERMISSOES_USUARIOS ' +
                   ' WHERE USU_CODIGO = ' + IntToStr(codUsuario) +
                   '   AND MEN_CODIGO = ' + IntToStr(codMenu);
    Open;
    if not IsEmpty then
    begin
      semDireitosTela := False;
      cbConsultar.Checked := FieldByName('PU_CONSULTAR').AsBoolean;
      cbIncluir.Checked := FieldByName('PU_NOVO').AsBoolean;
      cbAlterar.Checked := FieldByName('PU_ALTERAR').AsBoolean;
      cbExcluir.Checked := FieldByName('PU_APAGAR').AsBoolean;
    end
    else
    begin
      semDireitosTela := True;
      cbConsultar.Checked := False;
      cbIncluir.Checked := False;
      cbAlterar.Checked := False;
      cbExcluir.Checked := False;
    end;
  end;
end;

procedure TFrmPermissoesUsuarios.verificarPermissaoMenuPai(const no : TTreeNode);
begin
  with DMPrincipal.datasetAux do
  begin
    Close;
    CommandText := 'SELECT PU_CONSULTAR FROM PERMISSOES_USUARIOS WHERE USU_CODIGO = ' +
                   IntToStr(dbUsuarios.KeyValue) + ' AND MEN_CODIGO = ' + IntToStr(Integer(no.Data));
    Open;
    if IsEmpty then
    begin
      Close;
      CommandText := 'INSERT INTO PERMISSOES_USUARIOS (USU_CODIGO, MEN_CODIGO, PU_CONSULTAR) ' +
                     'VALUES (' + IntToStr(dbUsuarios.KeyValue) + ', ' + IntToStr(Integer(no.Data)) + ', ' +
                     BoolToStr(cbConsultar.Checked, True) + ')';
      ExecSQL(True);
    end
    else
    if not Fields[0].AsBoolean then
    begin
      Close;
      CommandText := 'UPDATE PERMISSOES_USUARIOS SET PU_CONSULTAR = True ' +
                     ' WHERE USU_CODIGO = ' + IntToStr(dbUsuarios.KeyValue) +
                     '   AND MEN_CODIGO = ' + IntToStr(Integer(no.Data));
      ExecSQL(True);
    end;
  end;
  if Assigned(no.Parent) then
    verificarPermissaoMenuPai(no.Parent);
end;

procedure TFrmPermissoesUsuarios.btnSalvarClick(Sender: TObject);
begin
  if not (cbConsultar.Checked) and ((cbIncluir.Checked) or (cbAlterar.Checked) or (cbExcluir.Checked)) then
    cbConsultar.Checked := True;
  with DMPrincipal.datasetAux do
  begin
    Close;
    if semDireitosTela then
      CommandText := 'INSERT INTO PERMISSOES_USUARIOS (USU_CODIGO, MEN_CODIGO, PU_NOVO, PU_ALTERAR, PU_APAGAR, PU_CONSULTAR) ' +
                     'VALUES (' + IntToStr(dbUsuarios.KeyValue) + ', ' + IntToStr(Integer(tvMenus.Selected.Data)) + ', ' +
                     BoolToStr(cbIncluir.Checked, True) + ', ' + BoolToStr(cbAlterar.Checked, True) + ', ' +
                     BoolToStr(cbExcluir.Checked, True) + ', ' + BoolToStr(cbConsultar.Checked, True) + ')'
    else
      CommandText := 'UPDATE PERMISSOES_USUARIOS SET ' +
                     'PU_NOVO = ' + BoolToStr(cbIncluir.Checked, True) + ', ' +
                     'PU_ALTERAR = ' + BoolToStr(cbAlterar.Checked, True) + ', ' +
                     'PU_APAGAR = ' + BoolToStr(cbExcluir.Checked, True) + ', ' +
                     'PU_CONSULTAR = ' + BoolToStr(cbConsultar.Checked, True) +
                     ' WHERE USU_CODIGO = ' + IntToStr(dbUsuarios.KeyValue) +
                     '   AND MEN_CODIGO = ' + IntToStr(Integer(tvMenus.Selected.Data));
    ExecSQL(True);
    if (Assigned(tvMenus.Selected.Parent)) and (cbConsultar.Checked) then
      verificarPermissaoMenuPai(tvMenus.Selected.Parent);
  end;
end;

procedure TFrmPermissoesUsuarios.tvMenusClick(Sender: TObject);
begin
  if Assigned(tvMenus.Selected) then
  begin
    HabilitarOpcoes(True);
    CarregarDireitosUsuarioMenu(dbUsuarios.KeyValue, Integer(tvMenus.Selected.Data));
    btnSalvar.Enabled := True;
  end;
end;
Frederico Brigatte***

Frederico Brigatte***

Curtidas 0

Respostas

Wilton Júnior

Wilton Júnior

24/04/2013

https://www.devmedia.com.br/boolean-no-delphi-com-banco-firebird/4102
Da uma lida nesse artigo, as vezes te ajuda.
GOSTEI 0
Joel Rodrigues

Joel Rodrigues

24/04/2013

Um exemplo:
cbConsultar.Checked := FieldByName('PU_CONSULTAR').AsString = 'S';
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

Ok, e nesse caso:


BoolToStr(cbExcluir.Checked, True)
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

Joel, pelo que me lembro acho que já fiz essa alteração e deu erro.
GOSTEI 0
Wilton Júnior

Wilton Júnior

24/04/2013

tem algo erra na função BoolToStr(cbIncluir.Checked, True)
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

Me ajuda, por favor, to doido, já, rs. Não sei mais o que fazer.
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

Ficaria assim:

cbConsultar.Checked := FieldByName('PU_CONSULTAR').AsString = 'S';
cbIncluir.Checked := FieldByName('PU_NOVO').AsString = 'S';
cbAlterar.Checked := FieldByName('PU_ALTERAR').AsString = 'S';
cbExcluir.Checked := FieldByName('PU_APAGAR').AsString = 'S';


E aqui?

  semDireitosTela := True;
  cbConsultar.Checked := False;
  cbIncluir.Checked := False;
  cbAlterar.Checked := False;
  cbExcluir.Checked := False;
GOSTEI 0
Joel Rodrigues

Joel Rodrigues

24/04/2013

Oxi, velho... aqui tu tá passando valores fixos. Quer mudar o que?

semDireitosTela := True;
cbConsultar.Checked := False;
cbIncluir.Checked := False;
cbAlterar.Checked := False;
cbExcluir.Checked := False;
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

Joel, vc tem skype? Quer que mande o projeto pra vc dar uma olhada? O banco era Interbase 7.5 usando boolean e mudei para Firebird com Char(1). A unit ta postada logo acima, não to conseguindo mudar.
GOSTEI 0
Joel Rodrigues

Joel Rodrigues

24/04/2013

Não, cara. Faz uns 500 anos que eu nem vejo o Firebird. Você não tá conseguindo alterar o que?
Vamos por parte. Vá alterando e vendo quais erros ocorrem.
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

Tem email ou skype? Eu estou trocando boolean por char(1). No código está true ou false, pq é lógico.
GOSTEI 0
Joel Rodrigues

Joel Rodrigues

24/04/2013

Certo, vamos por parte: QUAL FOI O ERRO QUE DEU? EM QUE PONTO DEU O ERRO?
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

Ta dando erro no código botão salvar:

Column unknow FALSE

Da esse erro qdo clica no botão salvar. Código do botão é esse:

procedure TFrmPermissoesUsuarios.btnSalvarClick(Sender: TObject);
begin
  if not (cbConsultar.Checked) and ((cbIncluir.Checked) or (cbAlterar.Checked) or (cbExcluir.Checked)) then
    cbConsultar.Checked := True;
  with DMPrincipal.datasetAux do
  begin
    Close;
    if semDireitosTela then
      CommandText := 'INSERT INTO PERMISSOES_USUARIOS (USU_CODIGO, MEN_CODIGO, PU_NOVO, PU_ALTERAR, PU_APAGAR, PU_CONSULTAR) ' +
                     'VALUES (' + IntToStr(dbUsuarios.KeyValue) + ', ' + IntToStr(Integer(tvMenus.Selected.Data)) + ', ' +
                     BoolToStr(cbIncluir.Checked, True) + ', ' + BoolToStr(cbAlterar.Checked, True) + ', ' +
                     BoolToStr(cbExcluir.Checked, True) + ', ' + BoolToStr(cbConsultar.Checked, True) + ')'
    else
      CommandText := 'UPDATE PERMISSOES_USUARIOS SET ' +
                     'PU_NOVO = ' + BoolToStr(cbIncluir.Checked, True) + ', ' +
                     'PU_ALTERAR = ' + BoolToStr(cbAlterar.Checked, True) + ', ' +
                     'PU_APAGAR = ' + BoolToStr(cbExcluir.Checked, True) + ', ' +
                     'PU_CONSULTAR = ' + BoolToStr(cbConsultar.Checked, True) +
                     ' WHERE USU_CODIGO = ' + IntToStr(dbUsuarios.KeyValue) +
                     '   AND MEN_CODIGO = ' + IntToStr(Integer(tvMenus.Selected.Data));
    ExecSQL(True);
    if (Assigned(tvMenus.Selected.Parent)) and (cbConsultar.Checked) then
      verificarPermissaoMenuPai(tvMenus.Selected.Parent);
  end;
end;
GOSTEI 0
Joel Rodrigues

Joel Rodrigues

24/04/2013

Coloque QuotedStr no BoolToStr, por exemplo:
QuotedStr(BoolToStr(cbIncluir.Checked, True))

Faça isso em todos os campos onde você está usando BoolToStr.
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

ok, vou fazer isso.
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

Fiz. Ficou assim:

CommandText := 'INSERT INTO PERMISSOES_USUARIOS (USU_CODIGO, MEN_CODIGO, PU_NOVO, PU_ALTERAR, PU_APAGAR, PU_CONSULTAR) ' +
                     'VALUES (' + IntToStr(dbUsuarios.KeyValue) + ', ' + IntToStr(Integer(tvMenus.Selected.Data)) + ', ' +
                     QuotedStr(BoolToStr(cbIncluir.Checked, True)) + ', ' + QuotedStr(BoolToStr(cbAlterar.Checked, True)) + ', ' + QuotedStr(BoolToStr(cbExcluir.Checked, True)) + ', ' + QuotedStr(BoolToStr(cbConsultar.Checked, True)) + ')'
    else
      CommandText := 'UPDATE PERMISSOES_USUARIOS SET ' +
                     'PU_NOVO = ' + QuotedStr(BoolToStr(cbIncluir.Checked, True)) + ', ' +
                     'PU_ALTERAR = ' + QuotedStr(BoolToStr(cbAlterar.Checked, True)) + ', ' +
                     'PU_APAGAR = ' + QuotedStr(BoolToStr(cbExcluir.Checked, True)) + ', ' +
                     'PU_CONSULTAR = ' + QuotedStr(BoolToStr(cbConsultar.Checked, True)) +
                     ' WHERE USU_CODIGO = ' + IntToStr(dbUsuarios.KeyValue) +
                     '   AND MEN_CODIGO = ' + IntToStr(Integer(tvMenus.Selected.Data));
    ExecSQL(True);





ao clicar no botão salvar deu o seguinte erro:

arithmetic exception, numeric overflow or string truncation string right truncation
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

Esqueci de perguntar, mas acho que ja respondeu, faço isso na unit inteira?
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

O que faz isso:

QuotedStr(BoolToStr(cbIncluir.Checked, True))


Para saber o que estou fazendo?
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

Joel, fiz na unit inteira e deu esse erro:

arithmetic exception, numeric overflow or string truncation string right truncation
GOSTEI 0
Joel Rodrigues

Joel Rodrigues

24/04/2013

Rapaz, eu só mandei colocar o QuotedStr pra pôr as aspas simples. Mas veja só. Seu campo é CHAR(1)?
Então nunca vai caber True/False, que é o que gera o BoolToStr. Você quer gravar S ou N, correto?
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

Sim, está como char(1). Mas mesmo assim esta dando esse erro. Mesmo só onde vc tinha falado.
GOSTEI 0
Joel Rodrigues

Joel Rodrigues

24/04/2013

Nesse caso, acho melhor você declarar variáveis para as 4 condições e defini-las como S ou N para usar no script.
Por exemplo:
if cbIncluir.Checked then
   incluir := 'S'
else
   incluir := 'N';

if cbAlterar.Checked then
   atlerar := 'S'
else
   alterar := 'N';


if cbExcluir.Checked then
   excluir:= 'S'
else
   excluir := 'N';


if cbConsultar.Checked then
   consultar := 'S'
else
   consultar := 'N';

CommandText := 'INSERT INTO PERMISSOES_USUARIOS (USU_CODIGO, MEN_CODIGO, PU_NOVO, PU_ALTERAR, PU_APAGAR, PU_CONSULTAR) ' +
'VALUES (' + IntToStr(dbUsuarios.KeyValue) + ', ' + IntToStr(Integer(tvMenus.Selected.Data)) + ', ' +
QuotedStr(incluir) + ', ' + QuotedStr(alterar) + ', ' + QuotedStr(excluir) + ', ' + QuotedStr(consultar) + ')'
else
CommandText := 'UPDATE PERMISSOES_USUARIOS SET ' +
'PU_NOVO = ' + QuotedStr(incluir) + ', ' +
'PU_ALTERAR = ' + QuotedStr(alterar) + ', ' +
'PU_APAGAR = ' + QuotedStr(excluir) + ', ' +
'PU_CONSULTAR = ' + QuotedStr(consultar) +
' WHERE USU_CODIGO = ' + IntToStr(dbUsuarios.KeyValue) +
' AND MEN_CODIGO = ' + IntToStr(Integer(tvMenus.Selected.Data));
ExecSQL(True);


Repare que aí tem 4 variáveis novas.
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

Testa isso la, né?
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

Ja fiz a alteração. Vou ter que dar uma saída agora. Mas volto logo pra testar, ok?
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

Deu um erro aqui:


Undeclared identifier: incluir, alterar, excluir, consultar.
GOSTEI 0
Joel Rodrigues

Joel Rodrigues

24/04/2013

Claro, amigo. Tem de declarar as variáveis incluir, alterar, excluir e consultar, né?
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

declaro como então? É string, isso?
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

Joel?
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

Joel,

var
incluir, alterar, excluir, consultar : String;

declaro no var da unit? Tipo String mesmo.
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

Joel, ta dando um erro de else aqui.

procedure TFrmPermissoesUsuarios.btnSalvarClick(Sender: TObject);
begin
  if not (cbConsultar.Checked) and ((cbIncluir.Checked) or (cbAlterar.Checked) or (cbExcluir.Checked)) then
    cbConsultar.Checked := True;
  with DMPrincipal.datasetAux do
  begin
    Close;
    if semDireitosTela then

      if cbIncluir.Checked then
         incluir := 'S'
      else
         incluir := 'N';

      if cbAlterar.Checked then
        alterar := 'S'
      else
        alterar := 'N';


      if cbExcluir.Checked then
        excluir:= 'S'
      else
        excluir := 'N';


      if cbConsultar.Checked then
         consultar := 'S'
      else
         consultar := 'N';

      CommandText := 'INSERT INTO PERMISSOES_USUARIOS (USU_CODIGO, MEN_CODIGO, PU_NOVO, PU_ALTERAR, PU_APAGAR, PU_CONSULTAR) ' +
                     'VALUES (' + IntToStr(dbUsuarios.KeyValue) + ', ' + IntToStr(Integer(tvMenus.Selected.Data)) + ', ' +
                     QuotedStr(Incluir) + ', ' + QuotedStr(Alterar) + ', ' +
                     QuotedStr(Excluir) + ', ' + QuotedStr(Consultar) + ')'
    else
      CommandText := 'UPDATE PERMISSOES_USUARIOS SET ' +
                     'PU_NOVO = ' + QuotedStr(Incluir) + ', ' +
                     'PU_ALTERAR = ' + QuotedStr(Alterar) + ', ' +
                     'PU_APAGAR = ' + QuotedStr(Excluir) + ', ' +
                     'PU_CONSULTAR = ' + QuotedStr(Consultar) +
                     ' WHERE USU_CODIGO = ' + IntToStr(dbUsuarios.KeyValue) +
                     '   AND MEN_CODIGO = ' + IntToStr(Integer(tvMenus.Selected.Data));
    ExecSQL(True);


    if (Assigned(tvMenus.Selected.Parent)) and (cbConsultar.Checked) then
      verificarPermissaoMenuPai(tvMenus.Selected.Parent);
  end;
end;


Onde está o erro?
GOSTEI 0
Joel Rodrigues

Joel Rodrigues

24/04/2013

Eu que pergunto. Em que linha ocorre e qual é exatamente o erro.
GOSTEI 0
Joel Rodrigues

Joel Rodrigues

24/04/2013

Ah, cara, falta um begin/end no if mais externo, já que foram inseridas mais linhas de código.
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

Eu coloquei antes do if not (cbConsultar.Checked) and ((cbIncluir.Checked) or (cbAlterar.Checked) or (cbExcluir.Checked)) then
cbConsultar.Checked := True; e deu certo. É lá mesmo que é pra colocar?
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

Joel, agora ta dando erro aqui:


procedure TFrmPermissoesUsuarios.verificarPermissaoMenuPai(const no : TTreeNode);
begin
  with DMPrincipal.datasetAux do
  begin
    Close;
    CommandText := 'SELECT PU_CONSULTAR FROM PERMISSOES_USUARIOS WHERE USU_CODIGO = ' +
                   IntToStr(dbUsuarios.KeyValue) + ' AND MEN_CODIGO = ' + IntToStr(Integer(no.Data));
    Open;
    if IsEmpty then
    begin
      Close;
      CommandText := 'INSERT INTO PERMISSOES_USUARIOS (USU_CODIGO, MEN_CODIGO, PU_CONSULTAR) ' +
                     'VALUES (' + IntToStr(dbUsuarios.KeyValue) + ', ' + IntToStr(Integer(no.Data)) + ', ' +
                     BoolToStr(cbConsultar.Checked, True) + ')';
      ExecSQL(True);
    end
    else
    if not Fields[0].AsBoolean then
    begin
      Close;
      CommandText := 'UPDATE PERMISSOES_USUARIOS SET PU_CONSULTAR = True ' +
                     ' WHERE USU_CODIGO = ' + IntToStr(dbUsuarios.KeyValue) +
                     '   AND MEN_CODIGO = ' + IntToStr(Integer(no.Data));
      ExecSQL(True);
    end;
  end;
  if Assigned(no.Parent) then
    verificarPermissaoMenuPai(no.Parent);
end;


// Esse chama do botão Salvar
verificarPermissaoMenuPai(tvMenus.Selected.Parent);  // Agora o erro é aqui


GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

Nesse caso aqui eu posso fazer igual ao anterior?


o erro deu nessa linha:
CommandText := 'INSERT INTO PERMISSOES_USUARIOS (USU_CODIGO, MEN_CODIGO, PU_CONSULTAR) ' +
                     'VALUES (' + IntToStr(dbUsuarios.KeyValue) + ', ' + IntToStr(Integer(no.Data)) + ', ' +
                     BoolToStr(cbConsultar.Checked, True) + ')';
ExecSQL(True);


Column unknown TRUE
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

E sobre esse erro aí?
GOSTEI 0
Joel Rodrigues

Joel Rodrigues

24/04/2013

Pode.
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

Veja se fiz certo: Já tinha feito isso, e tinha dado erro aqui:

procedure TFrmPermissoesUsuarios.verificarPermissaoMenuPai(const no : TTreeNode);
begin
      if cbIncluir.Checked then
         incluir := 'S'
      else
         incluir := 'N';

      if cbAlterar.Checked then
        alterar := 'S'
      else
        alterar := 'N';


      if cbExcluir.Checked then
        excluir:= 'S'
      else
        excluir := 'N';


      if cbConsultar.Checked then
         consultar := 'S'
      else
         consultar := 'N';

  with DMPrincipal.datasetAux do
  begin
    Close;
    CommandText := 'SELECT PU_CONSULTAR FROM PERMISSOES_USUARIOS WHERE USU_CODIGO = ' +
                   IntToStr(dbUsuarios.KeyValue) + ' AND MEN_CODIGO = ' + IntToStr(Integer(no.Data));
    Open;
    if IsEmpty then
    begin
      Close;
      CommandText := 'INSERT INTO PERMISSOES_USUARIOS (USU_CODIGO, MEN_CODIGO, PU_CONSULTAR) ' +
                     'VALUES (' + IntToStr(dbUsuarios.KeyValue) + ', ' + IntToStr(Integer(no.Data)) + ', ' +
                     BoolToStr(cbConsultar.Checked, True) + ')'; // aqui que tinha dado erro, nem compilou
      ExecSQL(True);
    end
    else
    if not Fields[0].AsBoolean then
    begin
      Close;
      CommandText := 'UPDATE PERMISSOES_USUARIOS SET PU_CONSULTAR = True ' +
                     ' WHERE USU_CODIGO = ' + IntToStr(dbUsuarios.KeyValue) +
                     '   AND MEN_CODIGO = ' + IntToStr(Integer(no.Data));
      ExecSQL(True);
    end;
  end;
  if Assigned(no.Parent) then
    verificarPermissaoMenuPai(no.Parent);
GOSTEI 0
Joel Rodrigues

Joel Rodrigues

24/04/2013

Onde tem BoolToStr(cbConsultar.Checked, True), como eu já disse, você vai precisar usar a variável "consultar", de acordo com os outros exemplos.
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

Está assim:

CommandText := 'INSERT INTO PERMISSOES_USUARIOS (USU_CODIGO, MEN_CODIGO, PU_CONSULTAR) ' +
               'VALUES (' + IntToStr(dbUsuarios.KeyValue) + ', ' + IntToStr(Integer(no.Data)) + ', ' +
                BoolToStr(cbConsultar.Checked, True) + ')';


Vai ficar assim:

CommandText := 'INSERT INTO PERMISSOES_USUARIOS (USU_CODIGO, MEN_CODIGO, PU_CONSULTAR) ' +
               'VALUES (' + IntToStr(dbUsuarios.KeyValue) + ', ' + IntToStr(Integer(no.Data)) + ', ' +
                + QuotedStr(Consultar) + ')';

GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

Erro ao compilar: (QuotedStr(Consultar))

CommandText := 'INSERT INTO PERMISSOES_USUARIOS (USU_CODIGO, MEN_CODIGO, PU_CONSULTAR) ' +
'VALUES (' + IntToStr(dbUsuarios.KeyValue) + ', ' + IntToStr(Integer(no.Data)) + ', ' +
+ QuotedStr(Consultar) + ')';


Operator not applicable to this operand type
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

O que fiz de errado?
GOSTEI 0
Joel Rodrigues

Joel Rodrigues

24/04/2013

"Consultar" está declarada como string?
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

Antes da seção implementation da unit untFrmPermissoesUsuarios está declarada assim:

var
  FrmPermissoesUsuarios: TFrmPermissoesUsuarios;
  incluir, alterar, excluir, consultar : String;
GOSTEI 0
Joel Rodrigues

Joel Rodrigues

24/04/2013

Então veja aí se você não tentou usar alguma função com argumento inválido.
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

Pior que não, ta assim mesmo. Quando dou F9 da esse erro mesmo.
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

Como assim argumento inválido? Fiz igual ao outro


      CommandText := 'INSERT INTO PERMISSOES_USUARIOS (USU_CODIGO, MEN_CODIGO, PU_CONSULTAR) ' +
                     'VALUES (' + IntToStr(dbUsuarios.KeyValue) + ', ' + IntToStr(Integer(no.Data)) + ', ' +
                     + QuotedStr(Consultar) + ')';

GOSTEI 0
Joel Rodrigues

Joel Rodrigues

24/04/2013

Poxa, só agora reparei. Cara, tem dois sinais de + aí. Um no final da segunda linha e um no início da terceira. Tira um.
GOSTEI 0
Frederico Brigatte***

Frederico Brigatte***

24/04/2013

Pior, que tem mesmo, Joel. Valeu pela dica. Vou ter que sair agora, mas pelo menos compilou. Vou testar qdo voltar e ai te falo. Obrigado por enquanto.
GOSTEI 0
POSTAR