I can create an access database with a colon in the field name, but I cant access it. I tried escaping the colon with single, double quotes and the backslash but didnt find a combo that worked.
The following code creates a 3 column access database with colons in the column name and attempts to insert values using every combination of quote and double quote
[code=20x50]
use DBI; #ppm install DBI
#ppm install DBD::ODBC
use Win32::OLE::Con st 'Microsoft DAO 3.6 Object Library';
my (
$acc, $db, $tab, $field, $dba, $sqlcmd, $sth, $file );
$file = 'hascolon.mdb';
unlink $file;
$acc = Win32::OLE->new("DAO.DBEng ine.36", 'quit');
$db = $acc->CreateDatabase ($file, dbLangGeneral);
$tab = $db->CreateTableDef ('TestTab');
$field = $tab->CreateField('T ryFor:Bit1',dbL ong);
$tab->Fields->Append($field) ;
$field = $tab->CreateField('T ryFor:Bit2',dbL ong);
$tab->Fields->Append($field) ;
$field = $tab->CreateField('T ryFor:Bit3',dbL ong);
$tab->Fields->Append($field) ;
$db->TableDefs->Append($tab) ;
$db->close();
$acc->close();
$dba = DBI->connect('dbi:O DBC:driver=micr osoft access driver (*.mdb);dbq='.
$file.'','','', {RaiseError => 0,PrintError=>1 });
$sqlcmd = 'INSERT INTO TestTab ([TryFor:Bit1], [TryFor:Bit2], [TryFor:Bit3]) VALUES (1,2,3);';
print "sqlcmd:$sqlcmd \n";
$sth = $dba->prepare($sqlcm d);
$sth->execute();
$sqlcmd = 'INSERT INTO TestTab ([TryFor\:Bit1], [TryFor\:Bit2], [TryFor\:Bit3]) VALUES (1,2,3);';
print "sqlcmd:$sqlcmd \n";
$sth = $dba->prepare($sqlcm d);
$sth->execute();
$sqlcmd = "INSERT INTO TestTab ([TryFor:Bit1], [TryFor:Bit2], [TryFor:Bit3]) VALUES (1,2,3);";
print "sqlcmd:$sqlcmd \n";
$sth = $dba->prepare($sqlcm d);
$sth->execute();
$sqlcmd = "INSERT INTO TestTab ([TryFor\:Bit1], [TryFor\:Bit2], [TryFor\:Bit3]) VALUES (1,2,3);";
print "sqlcmd:$sqlcmd \n";
$sth = $dba->prepare($sqlcm d);
$sth->execute();
[/code]
There are 4 error messages when executing the above script and this is the results:

If you remove the colon's from the source and rerun the modified code you will get this
The following code creates a 3 column access database with colons in the column name and attempts to insert values using every combination of quote and double quote
[code=20x50]
use DBI; #ppm install DBI
#ppm install DBD::ODBC
use Win32::OLE::Con st 'Microsoft DAO 3.6 Object Library';
my (
$acc, $db, $tab, $field, $dba, $sqlcmd, $sth, $file );
$file = 'hascolon.mdb';
unlink $file;
$acc = Win32::OLE->new("DAO.DBEng ine.36", 'quit');
$db = $acc->CreateDatabase ($file, dbLangGeneral);
$tab = $db->CreateTableDef ('TestTab');
$field = $tab->CreateField('T ryFor:Bit1',dbL ong);
$tab->Fields->Append($field) ;
$field = $tab->CreateField('T ryFor:Bit2',dbL ong);
$tab->Fields->Append($field) ;
$field = $tab->CreateField('T ryFor:Bit3',dbL ong);
$tab->Fields->Append($field) ;
$db->TableDefs->Append($tab) ;
$db->close();
$acc->close();
$dba = DBI->connect('dbi:O DBC:driver=micr osoft access driver (*.mdb);dbq='.
$file.'','','', {RaiseError => 0,PrintError=>1 });
$sqlcmd = 'INSERT INTO TestTab ([TryFor:Bit1], [TryFor:Bit2], [TryFor:Bit3]) VALUES (1,2,3);';
print "sqlcmd:$sqlcmd \n";
$sth = $dba->prepare($sqlcm d);
$sth->execute();
$sqlcmd = 'INSERT INTO TestTab ([TryFor\:Bit1], [TryFor\:Bit2], [TryFor\:Bit3]) VALUES (1,2,3);';
print "sqlcmd:$sqlcmd \n";
$sth = $dba->prepare($sqlcm d);
$sth->execute();
$sqlcmd = "INSERT INTO TestTab ([TryFor:Bit1], [TryFor:Bit2], [TryFor:Bit3]) VALUES (1,2,3);";
print "sqlcmd:$sqlcmd \n";
$sth = $dba->prepare($sqlcm d);
$sth->execute();
$sqlcmd = "INSERT INTO TestTab ([TryFor\:Bit1], [TryFor\:Bit2], [TryFor\:Bit3]) VALUES (1,2,3);";
print "sqlcmd:$sqlcmd \n";
$sth = $dba->prepare($sqlcm d);
$sth->execute();
[/code]
There are 4 error messages when executing the above script and this is the results:

If you remove the colon's from the source and rerun the modified code you will get this


Comment