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 -
use DBI; #ppm install DBI
-
#ppm install DBD::ODBC
-
use Win32::OLE::Const '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.DBEngine.36", 'quit');
-
$db = $acc->CreateDatabase($file, dbLangGeneral);
-
$tab = $db->CreateTableDef('TestTab');
-
$field = $tab->CreateField('TryFor:Bit1',dbLong);
-
$tab->Fields->Append($field);
-
$field = $tab->CreateField('TryFor:Bit2',dbLong);
-
$tab->Fields->Append($field);
-
$field = $tab->CreateField('TryFor:Bit3',dbLong);
-
$tab->Fields->Append($field);
-
$db->TableDefs->Append($tab);
-
$db->close();
-
$acc->close();
-
-
$dba = DBI->connect('dbi:ODBC:driver=microsoft 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($sqlcmd);
-
$sth->execute();
-
-
$sqlcmd = 'INSERT INTO TestTab ([TryFor\:Bit1], [TryFor\:Bit2], [TryFor\:Bit3]) VALUES (1,2,3);';
-
print "sqlcmd:$sqlcmd\n";
-
$sth = $dba->prepare($sqlcmd);
-
$sth->execute();
-
-
$sqlcmd = "INSERT INTO TestTab ([TryFor:Bit1], [TryFor:Bit2], [TryFor:Bit3]) VALUES (1,2,3);";
-
print "sqlcmd:$sqlcmd\n";
-
$sth = $dba->prepare($sqlcmd);
-
$sth->execute();
-
-
$sqlcmd = "INSERT INTO TestTab ([TryFor\:Bit1], [TryFor\:Bit2], [TryFor\:Bit3]) VALUES (1,2,3);";
-
print "sqlcmd:$sqlcmd\n";
-
$sth = $dba->prepare($sqlcmd);
-
$sth->execute();
-
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 4 3873
You need to find out how to escape it in the database, not in the perl code, maybe you need two slashes?
TryFor\\:Bit1
But I am just guessing. You may also want to look into placeholders, see the DBI documentation.
Hmm - use strict found a problem with $dba = DBI->
and I had to put a DBI:$dba = DBI->
before the $dba->quote() was accepted
I am looking at the problem. I think I should not be using Win32. It is strange that I could create the fields with a : using DAO but was unable to access them using DBI. Am reading up on the differences between them.
thanks.
Solved - Unaccountably, the problem was the [] and not the :
Worked: -
$qry = 'SELECT "TryFor:Bit1" FROM TestTAB';
-
$sth = $dbh->prepare($qry);
-
$sth->execute;
-
$sth->dump_results;
-
$dbh->disconnect;
-
However, I have not had any problem with any of my other code that uses the access []. For example, the following code had been working just fine tho I commented out that stupid : stuff as I didnt know what was happening at the time. -
my @RunThese = (
-
"DROP TABLE [##info];",
-
"SELECT [Employee Info].[Employee Name], [supervisorIDlookup].[email], [Employee Info].[Status], [Employee Info].[Employee ID], ".
-
" [Employee Info].[Department], [supervisorIDlookup].[EmployeeID], [Employee Info].[Status Date], [Employee Info].[Position Title], ".
-
# " [Employee Info].[SkillSoft:Bus-Select], [Employee Info].[SkillSoft:Bus-Full], [Employee Info].[SkillSoft:Desktop], [Employee Info].[SkillSoft:IT], ".
-
" [Employee Info].[Working on Degree] INTO [##info] FROM [Employee Info] INNER JOIN [supervisorIDlookup] on [Employee Info].[Supervisor] = [supervisorIDlookup].[LastName];",
-
-
I will have to go back and use single quote on the query and substitute double where that [] is about the SkillSoft:blahblah stuff
Another observation: The editor that I am using displays tags, but seems to get confused (or maybe I am) about which methods belong to which class.
For example
my DBI:$dbh;
$dbh-> does not get its methods listed, but
$dbh->quote( does as shown here
note that that $dbh->quote_identifier( has a different class and the arguments to that class do not match the ones referenced by Kevin (eWish)'s post here
I do not know why DBI was first used, then DBD and that suggests that one or the other of the code would not work. The quote_identifier listed in the reference took up to 4 args with the first being the catalog. That is not shown in the above method tooltip.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Frank Millman |
last post by:
Hi all
I am using odbc from win32 extensions to connect to MS SQL Server. I
use mx.DateTime to handle dates. When I select a datetime column from
the database, odbc returns something called a...
|
by: Christopher Subich |
last post by:
From the documentation, it looks like DParser-python will do what I
need, but I'm having trouble getting it installed properly. I'm using a
win32 environment, with official 2.4 Python binaries.
...
|
by: Frank Millman |
last post by:
Hi all
I am using win32 odbc to connect to SQL Server. I have just started
using the 'bit' data type, which is a boolean type which can store 1 or
0.
This works with win32, but it returns '1'...
|
by: sethi |
last post by:
Hi i m working on my high school project and trying to connect to MS Access database by using Perl though i 'm able to connect with the databse but was unable to extract data from the table in the...
|
by: enjoylife27 |
last post by:
Hi there,
I am using Perl 5.8 with Apache 2.2 on Win XP SP2, all configured and working fine. I am able to run perl programs from command prompt. I am also able to call CGI scripts from HTML pages...
|
by: rag84dec |
last post by:
Old Title: Someone please send the link to Win32::ODBC please
hi,
I want to work on Datababase programs thru perl.
I tried with DBI but i am unable to install DBI and DBD.
So someone pls...
|
by: rajiv07 |
last post by:
Hi to all,
I have use Win32::ODBC module to access Ms Access database.Here the Date Is not getting update.Could u Tell me the date format to update.
So for I have tried..
$q="update...
|
by: mikeodba |
last post by:
Summary: SQL3255 Reason code 2 from db2move with DB2 v9.1 fixpack 5.
on Win32.
Win32 DB2 version 9.1 fixpack5 , performing DB2MOVE COPY with
SCHEMAMAP between two local databases in the same...
|
by: BeemerBiker |
last post by:
I tried the following that didnt work
"c:\\new.mdb"
'c:\\new.mdb'
"c:\\new\.mdb"
So far, the only thing that worked is "c:\\new" but I had to rename the destination access database to get rid...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |