Problem with tinyint

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
WarForge00
Posts: 3
Joined: Sat 25 Mar 2006 17:56

Problem with tinyint

Post by WarForge00 » Sat 25 Mar 2006 18:01

Here's the database that I'm using...

CREATE TABLE `users` (
`userID` bigint(20) unsigned NOT NULL auto_increment,
`username` varchar(32) NOT NULL default '',
`password` varchar(32) NOT NULL default '',
`name` varchar(255) NOT NULL default '',
`active` tinyint(1) unsigned NOT NULL default '0',
`accountaccess` tinyint(1) unsigned NOT NULL default '0',
`adminaccess` tinyiny(1) unsigned NOT NULL default '0',
PRIMARY KEY (`userID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 PACK_KEYS=0 AUTO_INCREMENT=1 ;

INSERT INTO `users` VALUES (1, 'admin', '43e9a4ab75570f5b', 'Administrator', 1, 1, 1);

I have that on a remote MySQL database and an embedded localdatabase with just the table (no data in the local database). If I do the following code:

frmLogin.remoteQuery.SQL.Text := 'SELECT * FROM users';
frmLogin.remoteQuery.Open;
for i := 1 to frmLogin.remoteQuery.RecordCount do
begin
frmLogin.localQuery.SQL.Clear;
frmLogin.localQuery.SQL.Text := 'INSERT INTO users (userID, username, password, name, active, accountaccess, adminaccess) VALUES (' + inttostr(frmLogin.remoteQuery.FieldValues['userID']) + ', ' + QuotedStr(frmLogin.remoteQuery.FieldValues['username']) + ', ' + QuotedStr(frmLogin.remoteQuery.FieldValues['password']) + ', ' + QuotedStr(frmLogin.remoteQuery.FieldValues['name']) + ', ' + inttostr(frmLogin.remoteQuery.FieldValues['active']) + ', ' + inttostr(frmLogin.remoteQuery.FieldValues['accountaccess']) + ', ' + inttostr(frmLogin.remoteQuery.FieldValues['adminaccess']) + ')';
frmLogin.localQuery.Execute;

frmLogin.remoteQuery.Next;
end;

The values of active, accountaccess, and adminaccess all become true instead of 0 or 1.

WarForge00
Posts: 3
Joined: Sat 25 Mar 2006 17:56

Post by WarForge00 » Sat 25 Mar 2006 18:02

Forgot to add the following...

If i change the type from tinyint(1) to int(10), then the values stay as 1 or 0 and don't get changed to true or false.

GEswin
Posts: 186
Joined: Wed 03 Nov 2004 16:57
Location: Spain
Contact:

Post by GEswin » Sun 26 Mar 2006 22:16

Tinyint ( 1 ) is represented as boolean in MyDac components. This feature was introduced to use boolean fields together with mysql.

swierzbicki
Posts: 451
Joined: Wed 19 Jan 2005 09:59

Post by swierzbicki » Mon 27 Mar 2006 07:34

In your MyQuery / MyTable option :

EnableBoolean : Specifies a method of representation of TINYINT(1) fields. If set to True these fields will be represented as TBooleanFiled; otherwise, as TSmallintField. The default value is True;

Post Reply