Important Bug with simple code

Important Bug with simple code

Postby ziclope » Fri 24 Feb 2006 11:43

Hello,

I am inserting a simple record in database with the following code:

Code: Select all
TMyQuery * pQuery = new TMyQuery(NULL);
    pQuery->Connection = FormMain->Connection;

    pQuery->SQL->Text =
        "SELECT * FROM PERMISOS WHERE ID_PERMISOS = 0";
    pQuery->Open();

    //pQuery->SQL->Text =
    //    "SELECT * FROM PERMISOS WHERE ID_USUARIOS='" + FormMain->QueryUsuario->FieldByName("ID_USUARIOS")->Text +
    //    "' AND TABLA = '" + sTabla + "' AND CLAVE = '" + ClientDataSetMaster->FieldByName(sClave)->Text + "'";

    //pQuery->SQL->SaveToFile("sql.txt");

    pQuery->Insert();

    pQuery->FieldByName("TABLA")->Text = sTabla;
    pQuery->FieldByName("CLAVE")->Text = sClave;

    pQuery->FieldByName("ID_USUARIOS")->Text = FormMain->QueryUsuario->FieldByName("ID_USUARIOS")->Text;

    pQuery->FieldByName("OR")->Text = FormMain->QueryUsuario->FieldByName("OR_1")->Text;
    pQuery->FieldByName("OI")->Text = FormMain->QueryUsuario->FieldByName("OI_1")->Text;
    pQuery->FieldByName("OW")->Text = FormMain->QueryUsuario->FieldByName("OW_1")->Text;
    pQuery->FieldByName("OX")->Text = FormMain->QueryUsuario->FieldByName("OX_1")->Text;

    pQuery->Post();

    delete pQuery;


The SQL code:

Code: Select all
DROP TABLE IF EXISTS `zdb`.`permisos`;
CREATE TABLE  `zdb`.`permisos` (
  `ID_PERMISOS` int(10) unsigned NOT NULL auto_increment,
  `TABLA` varchar(100) default NULL,
  `CLAVE` varchar(45) default NULL,
  `ID_USUARIOS` char(3) default NULL,
  `TIPO` varchar(50) default NULL,
  `OR` int(11) default NULL,
  `OW` int(11) default NULL,
  `OX` int(11) default NULL,
  `OI` int(11) default NULL,
  `GR` int(11) default NULL,
  `GW` int(11) default NULL,
  `GX` int(11) default NULL,
  `GI` int(11) default NULL,
  `AR` int(11) default NULL,
  `AW` int(11) default NULL,
  `AX` int(11) default NULL,
  `AI` int(11) default NULL,
  PRIMARY KEY  (`ID_PERMISOS`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


When I post the record I get an exception that seem bad sql code.

I use C++Builder 6, MySQL 4.1.16 and MyDAC 4.30.0.10[/code]
ziclope
 
Posts: 26
Joined: Fri 24 Feb 2006 11:34

Postby ziclope » Fri 24 Feb 2006 11:55

Ok,

The problem is my FieldName: OR

it is confused by OR operator in SQL :).

Regards
ziclope
 
Posts: 26
Joined: Fri 24 Feb 2006 11:34


Return to MySQL Data Access Components