perl 5.8.9
大家好,
我成功使用DBI / DBD / ODBC在现有Access 2003(.mdb)数据库中使用以下字符串创建新表: $ q =“CREATE TABLE memoTestA(name TEXT,addr TEXT)”; #works
但我无法弄清楚如何添加MEMO类型的字段即 $ q =“CREATE TABLE memoTestB(name TEXT,addr TEXT,desc MEMO)”; #throws syntax error
必须有办法 - 诀窍是什么?
使用DBD :: ODBC切换到Win32 :: OLE的表格让我超越了 - >执行stmt抛出的“错误语法”错误, 但我没有看到实际在Access数据库中创建的表。 HM。
#-------------------------------
sub setUpDatasourceLocalAccessC($)
{ my $debug = 0;
my ( $dbFile) = @_;
#Choose appropriate version of Jet for your system
my $Jet = Win32::OLE->CreateObject('DAO.DBEngine.36') or die "Can't create Jet database engine.";
my $dbh = $Jet->OpenDatabase( $dbFile);
return $dbh;
}
#-------------------------------
sub createMemoTablePrepareC($)
{
my ($dbh_vdms) = @_;
print "entering createMemoTablePrepareC\n" if $debug;
my $errorHit = 0;
my @table_arry = ();
my @goodtable_arry = ();
my $q = undef;
if( !defined( $dbh_vdms)) {
_pushErrorMsg("db connection failed - ".$DBI::errstr);
$errorHit = 1;
} else {
$q = "CREATE TABLE memoTestC (name TEXT, addr TEXT)"; # works
$q = "CREATE TABLE memoTestC (name TEXT, addr TEXT, desc MEMO)"; #seems to work, no errmsg but dont see table appear in database
$dbh_vdms->Execute( $q);
if( my $errorMsg = $dbh_vdms->errstr ) {
_pushErrorMsg("create statement failed - ".$errorMsg);
$errorHit = 1;
}
$dbh_vdms->close();
$dbh_vdms->disconnect();
}
print "exiting createMemoTablePrepareC with errorHit=".$errorHit."\n" if $debug;
return $errorHit;
}
TIA,
仍在学习史蒂夫
答案 0 :(得分:0)
不要调用列“desc”,因为它是保留字。如果你想保留列名,你必须引用它,例如,创建表fred([desc] MEMO)。