473,397 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Win32::ODBC problem with colon in column name

BeemerBiker
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
Expand|Select|Wrap|Line Numbers
  1. use DBI;  #ppm install DBI
  2.           #ppm install DBD::ODBC
  3. use Win32::OLE::Const 'Microsoft DAO 3.6 Object Library';
  4.  
  5. my (
  6.  $acc, $db, $tab, $field, $dba, $sqlcmd, $sth, $file );
  7.  
  8. $file = 'hascolon.mdb';
  9. unlink $file;
  10.  
  11. $acc = Win32::OLE->new("DAO.DBEngine.36", 'quit');
  12. $db = $acc->CreateDatabase($file, dbLangGeneral);
  13. $tab = $db->CreateTableDef('TestTab');
  14. $field = $tab->CreateField('TryFor:Bit1',dbLong);
  15. $tab->Fields->Append($field);
  16. $field = $tab->CreateField('TryFor:Bit2',dbLong);
  17. $tab->Fields->Append($field);
  18. $field = $tab->CreateField('TryFor:Bit3',dbLong);
  19. $tab->Fields->Append($field);
  20. $db->TableDefs->Append($tab);
  21. $db->close();
  22. $acc->close();
  23.  
  24. $dba = DBI->connect('dbi:ODBC:driver=microsoft access driver (*.mdb);dbq='.
  25.     $file.'','','',{RaiseError => 0,PrintError=>1});
  26.  
  27. $sqlcmd = 'INSERT INTO TestTab ([TryFor:Bit1], [TryFor:Bit2], [TryFor:Bit3]) VALUES (1,2,3);';
  28. print "sqlcmd:$sqlcmd\n";
  29. $sth = $dba->prepare($sqlcmd);
  30. $sth->execute();
  31.  
  32. $sqlcmd = 'INSERT INTO TestTab ([TryFor\:Bit1], [TryFor\:Bit2], [TryFor\:Bit3]) VALUES (1,2,3);';
  33. print "sqlcmd:$sqlcmd\n";
  34. $sth = $dba->prepare($sqlcmd);
  35. $sth->execute();
  36.  
  37. $sqlcmd = "INSERT INTO TestTab ([TryFor:Bit1], [TryFor:Bit2], [TryFor:Bit3]) VALUES (1,2,3);";
  38. print "sqlcmd:$sqlcmd\n";
  39. $sth = $dba->prepare($sqlcmd);
  40. $sth->execute();
  41.  
  42. $sqlcmd = "INSERT INTO TestTab ([TryFor\:Bit1], [TryFor\:Bit2], [TryFor\:Bit3]) VALUES (1,2,3);";
  43. print "sqlcmd:$sqlcmd\n";
  44. $sth = $dba->prepare($sqlcmd);
  45. $sth->execute();
  46.  

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

Attached Files
File Type: zip src.zip (9.4 KB, 80 views)
Feb 24 '09 #1
4 3874
KevinADC
4,059 Expert 2GB
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.
Feb 24 '09 #2
eWish
971 Expert 512MB
Look into quote or use placeholders and bind values with the DBI. This will escape the characters for you.

--Kevin
Feb 24 '09 #3
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.
Feb 25 '09 #4
Solved - Unaccountably, the problem was the [] and not the :

Worked:
Expand|Select|Wrap|Line Numbers
  1. $qry = 'SELECT "TryFor:Bit1" FROM TestTAB';
  2. $sth = $dbh->prepare($qry);
  3. $sth->execute;
  4. $sth->dump_results;
  5. $dbh->disconnect;
  6.  
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.
Expand|Select|Wrap|Line Numbers
  1. my @RunThese = (
  2. "DROP TABLE [##info];",
  3. "SELECT [Employee Info].[Employee Name], [supervisorIDlookup].[email], [Employee Info].[Status], [Employee Info].[Employee ID], ".
  4.  " [Employee Info].[Department],  [supervisorIDlookup].[EmployeeID], [Employee Info].[Status Date], [Employee Info].[Position Title], ".
  5. # " [Employee Info].[SkillSoft:Bus-Select], [Employee Info].[SkillSoft:Bus-Full], [Employee Info].[SkillSoft:Desktop], [Employee Info].[SkillSoft:IT], ".
  6.  " [Employee Info].[Working on Degree]  INTO [##info] FROM [Employee Info] INNER JOIN [supervisorIDlookup] on [Employee Info].[Supervisor] = [supervisorIDlookup].[LastName];",
  7.  
  8.  
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.
Feb 25 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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...
2
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. ...
0
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'...
0
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...
3
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...
5
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...
1
rajiv07
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...
0
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...
3
BeemerBiker
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.