Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

899 lines
22 KiB

  1. package Win32::ODBC;
  2. $VERSION = '0.03';
  3. # Win32::ODBC.pm
  4. # +==========================================================+
  5. # | |
  6. # | ODBC.PM package |
  7. # | --------------- |
  8. # | |
  9. # | Copyright (c) 1996, 1997 Dave Roth. All rights reserved. |
  10. # | This program is free software; you can redistribute |
  11. # | it and/or modify it under the same terms as Perl itself. |
  12. # | |
  13. # +==========================================================+
  14. #
  15. #
  16. # based on original code by Dan DeMaggio ([email protected])
  17. #
  18. # Use under GNU General Public License or Larry Wall's "Artistic License"
  19. #
  20. # Check the README.TXT file that comes with this package for details about
  21. # it's history.
  22. #
  23. require Exporter;
  24. require DynaLoader;
  25. $ODBCPackage = "Win32::ODBC";
  26. $ODBCPackage::Version = 970208;
  27. $::ODBC = $ODBCPackage;
  28. $CacheConnection = 0;
  29. # Reserve ODBC in the main namespace for US!
  30. *ODBC::=\%Win32::ODBC::;
  31. @ISA= qw( Exporter DynaLoader );
  32. # Items to export into callers namespace by default. Note: do not export
  33. # names by default without a very good reason. Use EXPORT_OK instead.
  34. # Do not simply export all your public functions/methods/constants.
  35. @EXPORT = qw(
  36. ODBC_ADD_DSN
  37. ODBC_REMOVE_DSN
  38. ODBC_CONFIG_DSN
  39. SQL_DONT_CLOSE
  40. SQL_DROP
  41. SQL_CLOSE
  42. SQL_UNBIND
  43. SQL_RESET_PARAMS
  44. SQL_FETCH_NEXT
  45. SQL_FETCH_FIRST
  46. SQL_FETCH_LAST
  47. SQL_FETCH_PRIOR
  48. SQL_FETCH_ABSOLUTE
  49. SQL_FETCH_RELATIVE
  50. SQL_FETCH_BOOKMARK
  51. SQL_COLUMN_COUNT
  52. SQL_COLUMN_NAME
  53. SQL_COLUMN_TYPE
  54. SQL_COLUMN_LENGTH
  55. SQL_COLUMN_PRECISION
  56. SQL_COLUMN_SCALE
  57. SQL_COLUMN_DISPLAY_SIZE
  58. SQL_COLUMN_NULLABLE
  59. SQL_COLUMN_UNSIGNED
  60. SQL_COLUMN_MONEY
  61. SQL_COLUMN_UPDATABLE
  62. SQL_COLUMN_AUTO_INCREMENT
  63. SQL_COLUMN_CASE_SENSITIVE
  64. SQL_COLUMN_SEARCHABLE
  65. SQL_COLUMN_TYPE_NAME
  66. SQL_COLUMN_TABLE_NAME
  67. SQL_COLUMN_OWNER_NAME
  68. SQL_COLUMN_QUALIFIER_NAME
  69. SQL_COLUMN_LABEL
  70. SQL_COLATT_OPT_MAX
  71. SQL_COLUMN_DRIVER_START
  72. SQL_COLATT_OPT_MIN
  73. SQL_ATTR_READONLY
  74. SQL_ATTR_WRITE
  75. SQL_ATTR_READWRITE_UNKNOWN
  76. SQL_UNSEARCHABLE
  77. SQL_LIKE_ONLY
  78. SQL_ALL_EXCEPT_LIKE
  79. SQL_SEARCHABLE
  80. );
  81. #The above are included for backward compatibility
  82. sub new
  83. {
  84. my ($n, $self);
  85. my ($type) = shift;
  86. my ($DSN) = shift;
  87. my (@Results) = @_;
  88. if (ref $DSN){
  89. @Results = ODBCClone($DSN->{'connection'});
  90. }else{
  91. @Results = ODBCConnect($DSN, @Results);
  92. }
  93. @Results = processError(-1, @Results);
  94. if (! scalar(@Results)){
  95. return undef;
  96. }
  97. $self = bless {};
  98. $self->{'connection'} = $Results[0];
  99. $ErrConn = $Results[0];
  100. $ErrText = $Results[1];
  101. $ErrNum = 0;
  102. $self->{'DSN'} = $DSN;
  103. $self;
  104. }
  105. ####
  106. # Close this ODBC session (or all sessions)
  107. ####
  108. sub Close
  109. {
  110. my ($self, $Result) = shift;
  111. $Result = DESTROY($self);
  112. $self->{'connection'} = -1;
  113. return $Result;
  114. }
  115. ####
  116. # Auto-Kill an instance of this module
  117. ####
  118. sub DESTROY
  119. {
  120. my ($self) = shift;
  121. my (@Results) = (0);
  122. if($self->{'connection'} > -1){
  123. @Results = ODBCDisconnect($self->{'connection'});
  124. @Results = processError($self, @Results);
  125. if ($Results[0]){
  126. undef $self->{'DSN'};
  127. undef @{$self->{'fnames'}};
  128. undef %{$self->{'field'}};
  129. undef %{$self->{'connection'}};
  130. }
  131. }
  132. return $Results[0];
  133. }
  134. sub sql{
  135. return (Sql(@_));
  136. }
  137. ####
  138. # Submit an SQL Execute statement for processing
  139. ####
  140. sub Sql{
  141. my ($self, $Sql, @Results) = @_;
  142. @Results = ODBCExecute($self->{'connection'}, $Sql);
  143. return updateResults($self, @Results);
  144. }
  145. ####
  146. # Retrieve data from a particular field
  147. ####
  148. sub Data{
  149. # Change by JOC 06-APR-96
  150. # Altered by Dave Roth <[email protected]> 96.05.07
  151. my($self) = shift;
  152. my(@Fields) = @_;
  153. my(@Results, $Results, $Field);
  154. if ($self->{'Dirty'}){
  155. GetData($self);
  156. $self->{'Dirty'} = 0;
  157. }
  158. @Fields = @{$self->{'fnames'}} if (! scalar(@Fields));
  159. foreach $Field (@Fields) {
  160. if (wantarray) {
  161. push(@Results, data($self, $Field));
  162. } else {
  163. $Results .= data($self, $Field);
  164. }
  165. }
  166. return wantarray ? @Results : $Results;
  167. }
  168. sub DataHash{
  169. my($self, @Results) = @_;
  170. my(%Results, $Element);
  171. if ($self->{'Dirty'}){
  172. GetData($self);
  173. $self->{'Dirty'} = 0;
  174. }
  175. @Results = @{$self->{'fnames'}} if (! scalar(@Results));
  176. foreach $Element (@Results) {
  177. $Results{$Element} = data($self, $Element);
  178. }
  179. return %Results;
  180. }
  181. ####
  182. # Retrieve data from the data buffer
  183. ####
  184. sub data
  185. { $_[0]->{'data'}->{$_[1]}; }
  186. sub fetchrow{
  187. return (FetchRow(@_));
  188. }
  189. ####
  190. # Put a row from an ODBC data set into data buffer
  191. ####
  192. sub FetchRow{
  193. my ($self, @Results) = @_;
  194. my ($item, $num, $sqlcode);
  195. # Added by JOC 06-APR-96
  196. # $num = 0;
  197. $num = 0;
  198. undef $self->{'data'};
  199. @Results = ODBCFetch($self->{'connection'}, @Results);
  200. if (! (@Results = processError($self, @Results))){
  201. ####
  202. # There should be an innocuous error "No records remain"
  203. # This indicates no more records in the dataset
  204. ####
  205. return undef;
  206. }
  207. # Set the Dirty bit so we will go and extract data via the
  208. # ODBCGetData function. Otherwise use the cache.
  209. $self->{'Dirty'} = 1;
  210. # Return the array of field Results.
  211. return @Results;
  212. }
  213. sub GetData{
  214. my($self) = @_;
  215. my(@Results, $num);
  216. @Results = ODBCGetData($self->{'connection'});
  217. if (!(@Results = processError($self, @Results))){
  218. return undef;
  219. }
  220. ####
  221. # This is a special case. Do not call processResults
  222. ####
  223. ClearError();
  224. foreach (@Results){
  225. s/ +$//; # HACK
  226. $self->{'data'}->{ ${$self->{'fnames'}}[$num] } = $_;
  227. $num++;
  228. }
  229. # return is a hack to interface with a assoc array.
  230. return wantarray? (1, 1): 1;
  231. }
  232. ####
  233. # See if any more ODBC Results Sets
  234. # Added by Brian Dunfordshore <[email protected]>
  235. # 96.07.10
  236. ####
  237. sub MoreResults{
  238. my ($self) = @_;
  239. my(@Results) = ODBCMoreResults($self->{'connection'});
  240. return (processError($self, @Results))[0];
  241. }
  242. ####
  243. # Retrieve the catalog from the current DSN
  244. # NOTE: All Field names are uppercase!!!
  245. ####
  246. sub Catalog{
  247. my ($self) = shift;
  248. my ($Qualifier, $Owner, $Name, $Type) = @_;
  249. my (@Results) = ODBCTableList($self->{'connection'}, $Qualifier, $Owner, $Name, $Type);
  250. # If there was an error return 0 else 1
  251. return (updateResults($self, @Results) != 1);
  252. }
  253. ####
  254. # Return an array of names from the catalog for the current DSN
  255. # TableList($Qualifier, $Owner, $Name, $Type)
  256. # Return: (array of names of tables)
  257. # NOTE: All Field names are uppercase!!!
  258. ####
  259. sub TableList{
  260. my ($self) = shift;
  261. my (@Results) = @_;
  262. if (! scalar(@Results)){
  263. @Results = ("", "", "%", "TABLE");
  264. }
  265. if (! Catalog($self, @Results)){
  266. return undef;
  267. }
  268. undef @Results;
  269. while (FetchRow($self)){
  270. push(@Results, Data($self, "TABLE_NAME"));
  271. }
  272. return sort(@Results);
  273. }
  274. sub fieldnames{
  275. return (FieldNames(@_));
  276. }
  277. ####
  278. # Return an array of fieldnames extracted from the current dataset
  279. ####
  280. sub FieldNames { $self = shift; return @{$self->{'fnames'}}; }
  281. ####
  282. # Closes this connection. This is used mostly for testing. You should
  283. # probably use Close().
  284. ####
  285. sub ShutDown{
  286. my($self) = @_;
  287. print "\nClosing connection $self->{'connection'}...";
  288. $self->Close();
  289. print "\nDone\n";
  290. }
  291. ####
  292. # Return this connection number
  293. ####
  294. sub Connection{
  295. my($self) = @_;
  296. return $self->{'connection'};
  297. }
  298. ####
  299. # Returns the current connections that are in use.
  300. ####
  301. sub GetConnections{
  302. return ODBCGetConnections();
  303. }
  304. ####
  305. # Set the Max Buffer Size for this connection. This determines just how much
  306. # ram can be allocated when a fetch() is performed that requires a HUGE amount
  307. # of memory. The default max is 10k and the absolute max is 100k.
  308. # This will probably never be used but I put it in because I noticed a fetch()
  309. # of a MEMO field in an Access table was something like 4Gig. Maybe I did
  310. # something wrong, but after checking several times I decided to impliment
  311. # this limit thingie.
  312. ####
  313. sub SetMaxBufSize{
  314. my($self, $Size) = @_;
  315. my(@Results) = ODBCSetMaxBufSize($self->{'connection'}, $Size);
  316. return (processError($self, @Results))[0];
  317. }
  318. ####
  319. # Returns the Max Buffer Size for this connection. See SetMaxBufSize().
  320. ####
  321. sub GetMaxBufSize{
  322. my($self) = @_;
  323. my(@Results) = ODBCGetMaxBufSize($self->{'connection'});
  324. return (processError($self, @Results))[0];
  325. }
  326. ####
  327. # Returns the DSN for this connection as an associative array.
  328. ####
  329. sub GetDSN{
  330. my($self, $DSN) = @_;
  331. if(! ref($self)){
  332. $DSN = $self;
  333. $self = 0;
  334. }
  335. if (! $DSN){
  336. $self = $self->{'connection'};
  337. }
  338. my(@Results) = ODBCGetDSN($self, $DSN);
  339. return (processError($self, @Results));
  340. }
  341. ####
  342. # Returns an associative array of $XXX{'DSN'}=Description
  343. ####
  344. sub DataSources{
  345. my($self, $DSN) = @_;
  346. if(! ref $self){
  347. $DSN = $self;
  348. $self = 0;
  349. }
  350. my(@Results) = ODBCDataSources($DSN);
  351. return (processError($self, @Results));
  352. }
  353. ####
  354. # Returns an associative array of $XXX{'Driver Name'}=Driver Attributes
  355. ####
  356. sub Drivers{
  357. my($self) = @_;
  358. if(! ref $self){
  359. $self = 0;
  360. }
  361. my(@Results) = ODBCDrivers();
  362. return (processError($self, @Results));
  363. }
  364. ####
  365. # Returns the number of Rows that were affected by the previous SQL command.
  366. ####
  367. sub RowCount{
  368. my($self, $Connection) = @_;
  369. if (! ref($self)){
  370. $Connection = $self;
  371. $self = 0;
  372. }
  373. if (! $Connection){$Connection = $self->{'connection'};}
  374. my(@Results) = ODBCRowCount($Connection);
  375. return (processError($self, @Results))[0];
  376. }
  377. ####
  378. # Returns the Statement Close Type -- how does ODBC Close a statment.
  379. # Types:
  380. # SQL_DROP
  381. # SQL_CLOSE
  382. # SQL_UNBIND
  383. # SQL_RESET_PARAMS
  384. ####
  385. sub GetStmtCloseType{
  386. my($self, $Connection) = @_;
  387. if (! ref($self)){
  388. $Connection = $self;
  389. $self = 0;
  390. }
  391. if (! $Connection){$Connection = $self->{'connection'};}
  392. my(@Results) = ODBCGetStmtCloseType($Connection);
  393. return (processError($self, @Results));
  394. }
  395. ####
  396. # Sets the Statement Close Type -- how does ODBC Close a statment.
  397. # Types:
  398. # SQL_DROP
  399. # SQL_CLOSE
  400. # SQL_UNBIND
  401. # SQL_RESET_PARAMS
  402. # Returns the newly set value.
  403. ####
  404. sub SetStmtCloseType{
  405. my($self, $Type, $Connection) = @_;
  406. if (! ref($self)){
  407. $Connection = $Type;
  408. $Type = $self;
  409. $self = 0;
  410. }
  411. if (! $Connection){$Connection = $self->{'connection'};}
  412. my(@Results) = ODBCSetStmtCloseType($Connection, $Type);
  413. return (processError($self, @Results))[0];
  414. }
  415. sub ColAttributes{
  416. my($self, $Type, @Field) = @_;
  417. my(%Results, @Results, $Results, $Attrib, $Connection, $Temp);
  418. if (! ref($self)){
  419. $Type = $Field;
  420. $Field = $self;
  421. $self = 0;
  422. }
  423. $Connection = $self->{'connection'};
  424. if (! scalar(@Field)){ @Field = $self->fieldnames;}
  425. foreach $Temp (@Field){
  426. @Results = ODBCColAttributes($Connection, $Temp, $Type);
  427. ($Attrib) = processError($self, @Results);
  428. if (wantarray){
  429. $Results{$Temp} = $Attrib;
  430. }else{
  431. $Results .= "$Temp";
  432. }
  433. }
  434. return wantarray? %Results:$Results;
  435. }
  436. sub GetInfo{
  437. my($self, $Type) = @_;
  438. my($Connection, @Results);
  439. if(! ref $self){
  440. $Type = $self;
  441. $self = 0;
  442. $Connection = 0;
  443. }else{
  444. $Connection = $self->{'connection'};
  445. }
  446. @Results = ODBCGetInfo($Connection, $Type);
  447. return (processError($self, @Results))[0];
  448. }
  449. sub GetConnectOption{
  450. my($self, $Type) = @_;
  451. my(@Results);
  452. if(! ref $self){
  453. $Type = $self;
  454. $self = 0;
  455. }
  456. @Results = ODBCGetConnectOption($self->{'connection'}, $Type);
  457. return (processError($self, @Results))[0];
  458. }
  459. sub SetConnectOption{
  460. my($self, $Type, $Value) = @_;
  461. if(! ref $self){
  462. $Value = $Type;
  463. $Type = $self;
  464. $self = 0;
  465. }
  466. my(@Results) = ODBCSetConnectOption($self->{'connection'}, $Type, $Value);
  467. return (processError($self, @Results))[0];
  468. }
  469. sub Transact{
  470. my($self, $Type) = @_;
  471. my(@Results);
  472. if(! ref $self){
  473. $Type = $self;
  474. $self = 0;
  475. }
  476. @Results = ODBCTransact($self->{'connection'}, $Type);
  477. return (processError($self, @Results))[0];
  478. }
  479. sub SetPos{
  480. my($self, @Results) = @_;
  481. @Results = ODBCSetPos($self->{'connection'}, @Results);
  482. $self->{'Dirty'} = 1;
  483. return (processError($self, @Results))[0];
  484. }
  485. sub ConfigDSN{
  486. my($self) = shift @_;
  487. my($Type, $Connection);
  488. if(! ref $self){
  489. $Type = $self;
  490. $Connection = 0;
  491. $self = 0;
  492. }else{
  493. $Type = shift @_;
  494. $Connection = $self->{'connection'};
  495. }
  496. my($Driver, @Attributes) = @_;
  497. @Results = ODBCConfigDSN($Connection, $Type, $Driver, @Attributes);
  498. return (processError($self, @Results))[0];
  499. }
  500. sub Version{
  501. my($self, @Packages) = @_;
  502. my($Temp, @Results);
  503. if (! ref($self)){
  504. push(@Packages, $self);
  505. }
  506. my($ExtName, $ExtVersion) = Info();
  507. if (! scalar(@Packages)){
  508. @Packages = ("ODBC.PM", "ODBC.PLL");
  509. }
  510. foreach $Temp (@Packages){
  511. if ($Temp =~ /pll/i){
  512. push(@Results, "ODBC.PM:$Win32::ODBC::Version");
  513. }elsif ($Temp =~ /pm/i){
  514. push(@Results, "ODBC.PLL:$ExtVersion");
  515. }
  516. }
  517. return @Results;
  518. }
  519. sub SetStmtOption{
  520. my($self, $Option, $Value) = @_;
  521. if(! ref $self){
  522. $Value = $Option;
  523. $Option = $self;
  524. $self = 0;
  525. }
  526. my(@Results) = ODBCSetStmtOption($self->{'connection'}, $Option, $Value);
  527. return (processError($self, @Results))[0];
  528. }
  529. sub GetStmtOption{
  530. my($self, $Type) = @_;
  531. if(! ref $self){
  532. $Type = $self;
  533. $self = 0;
  534. }
  535. my(@Results) = ODBCGetStmtOption($self->{'connection'}, $Type);
  536. return (processError($self, @Results))[0];
  537. }
  538. sub GetFunctions{
  539. my($self, @Results)=@_;
  540. @Results = ODBCGetFunctions($self->{'connection'}, @Results);
  541. return (processError($self, @Results));
  542. }
  543. sub DropCursor{
  544. my($self) = @_;
  545. my(@Results) = ODBCDropCursor($self->{'connection'});
  546. return (processError($self, @Results))[0];
  547. }
  548. sub SetCursorName{
  549. my($self, $Name) = @_;
  550. my(@Results) = ODBCSetCursorName($self->{'connection'}, $Name);
  551. return (processError($self, @Results))[0];
  552. }
  553. sub GetCursorName{
  554. my($self) = @_;
  555. my(@Results) = ODBCGetCursorName($self->{'connection'});
  556. return (processError($self, @Results))[0];
  557. }
  558. sub GetSQLState{
  559. my($self) = @_;
  560. my(@Results) = ODBCGetSQLState($self->{'connection'});
  561. return (processError($self, @Results))[0];
  562. }
  563. # ----------- R e s u l t P r o c e s s i n g F u n c t i o n s ----------
  564. ####
  565. # Generic processing of data into associative arrays
  566. ####
  567. sub updateResults{
  568. my ($self, $Error, @Results) = @_;
  569. undef %{$self->{'field'}};
  570. ClearError($self);
  571. if ($Error){
  572. SetError($self, $Results[0], $Results[1]);
  573. return ($Error);
  574. }
  575. @{$self->{'fnames'}} = @Results;
  576. foreach (0..$#{$self->{'fnames'}}){
  577. s/ +$//;
  578. $self->{'field'}->{${$self->{'fnames'}}[$_]} = $_;
  579. }
  580. return undef;
  581. }
  582. # ----------------------------------------------------------------------------
  583. # ----------------- D e b u g g i n g F u n c t i o n s --------------------
  584. sub Debug{
  585. my($self, $iDebug, $File) = @_;
  586. my(@Results);
  587. if (! ref($self)){
  588. if (defined $self){
  589. $File = $iDebug;
  590. $iDebug = $self;
  591. }
  592. $Connection = 0;
  593. $self = 0;
  594. }else{
  595. $Connection = $self->{'connection'};
  596. }
  597. push(@Results, ($Connection, $iDebug));
  598. push(@Results, $File) if ($File ne "");
  599. @Results = ODBCDebug(@Results);
  600. return (processError($self, @Results))[0];
  601. }
  602. ####
  603. # Prints out the current dataset (used mostly for testing)
  604. ####
  605. sub DumpData {
  606. my($self) = @_; my($f, $goo);
  607. # Changed by JOC 06-Apr-96
  608. # print "\nDumping Data for connection: $conn->{'connection'}\n";
  609. print "\nDumping Data for connection: $self->{'connection'}\n";
  610. print "Error: \"";
  611. print $self->Error();
  612. print "\"\n";
  613. if (! $self->Error()){
  614. foreach $f ($self->FieldNames){
  615. print $f . " ";
  616. $goo .= "-" x length($f);
  617. $goo .= " ";
  618. }
  619. print "\n$goo\n";
  620. while ($self->FetchRow()){
  621. foreach $f ($self->FieldNames){
  622. print $self->data($f) . " ";
  623. }
  624. print "\n";
  625. }
  626. }
  627. }
  628. sub DumpError{
  629. my($self) = @_;
  630. my($ErrNum, $ErrText, $ErrConn);
  631. my($Temp);
  632. print "\n---------- Error Report: ----------\n";
  633. if (ref $self){
  634. ($ErrNum, $ErrText, $ErrConn) = $self->Error();
  635. ($Temp = $self->GetDSN()) =~ s/.*DSN=(.*?);.*/$1/i;
  636. print "Errors for \"$Temp\" on connection " . $self->{'connection'} . ":\n";
  637. }else{
  638. ($ErrNum, $ErrText, $ErrConn) = Error();
  639. print "Errors for the package:\n";
  640. }
  641. print "Connection Number: $ErrConn\nError number: $ErrNum\nError message: \"$ErrText\"\n";
  642. print "-----------------------------------\n";
  643. }
  644. ####
  645. # Submit an SQL statement and print data about it (used mostly for testing)
  646. ####
  647. sub Run{
  648. my($self, $Sql) = @_;
  649. print "\nExcecuting connection $self->{'connection'}\nsql statement: \"$Sql\"\n";
  650. $self->sql($Sql);
  651. print "Error: \"";
  652. print $self->error;
  653. print "\"\n";
  654. print "--------------------\n\n";
  655. }
  656. # ----------------------------------------------------------------------------
  657. # ----------- E r r o r P r o c e s s i n g F u n c t i o n s ------------
  658. ####
  659. # Process Errors returned from a call to ODBCxxxx().
  660. # It is assumed that the Win32::ODBC function returned the following structure:
  661. # ($ErrorNumber, $ResultsText, ...)
  662. # $ErrorNumber....0 = No Error
  663. # >0 = Error Number
  664. # $ResultsText.....if no error then this is the first Results element.
  665. # if error then this is the error text.
  666. ####
  667. sub processError{
  668. my($self, $Error, @Results) = @_;
  669. if ($Error){
  670. SetError($self, $Results[0], $Results[1]);
  671. undef @Results;
  672. }
  673. return @Results;
  674. }
  675. ####
  676. # Return the last recorded error message
  677. ####
  678. sub error{
  679. return (Error(@_));
  680. }
  681. sub Error{
  682. my($self) = @_;
  683. if(ref($self)){
  684. if($self->{'ErrNum'}){
  685. my($State) = ODBCGetSQLState($self->{'connection'});
  686. return (wantarray)? ($self->{'ErrNum'}, $self->{'ErrText'}, $self->{'connection'}, $State) :"[$self->{'ErrNum'}] [$self->{'connection'}] [$State] \"$self->{'ErrText'}\"";
  687. }
  688. }elsif ($ErrNum){
  689. return (wantarray)? ($ErrNum, $ErrText, $ErrConn):"[$ErrNum] [$ErrConn] \"$ErrText\"";
  690. }
  691. return undef
  692. }
  693. ####
  694. # SetError:
  695. # Assume that if $self is not a reference then it is just a placeholder
  696. # and should be ignored.
  697. ####
  698. sub SetError{
  699. my($self, $Num, $Text, $Conn) = @_;
  700. if (ref $self){
  701. $self->{'ErrNum'} = $Num;
  702. $self->{'ErrText'} = $Text;
  703. $Conn = $self->{'connection'} if ! $Conn;
  704. }
  705. $ErrNum = $Num;
  706. $ErrText = $Text;
  707. ####
  708. # Test Section Begin
  709. ####
  710. # $! = ($Num, $Text);
  711. ####
  712. # Test Section End
  713. ####
  714. $ErrConn = $Conn;
  715. }
  716. sub ClearError{
  717. my($self, $Num, $Text) = @_;
  718. if (ref $self){
  719. undef $self->{'ErrNum'};
  720. undef $self->{'ErrText'};
  721. }else{
  722. undef $ErrConn;
  723. undef $ErrNum;
  724. undef $ErrText;
  725. }
  726. ODBCCleanError();
  727. return 1;
  728. }
  729. sub GetError{
  730. my($self, $Connection) = @_;
  731. my(@Results);
  732. if (! ref($self)){
  733. $Connection = $self;
  734. $self = 0;
  735. }else{
  736. if (! defined($Connection)){
  737. $Connection = $self->{'connection'};
  738. }
  739. }
  740. @Results = ODBCGetError($Connection);
  741. return @Results;
  742. }
  743. # ----------------------------------------------------------------------------
  744. # ------------------ A U T O L O A D F U N C T I O N -----------------------
  745. sub AUTOLOAD {
  746. # This AUTOLOAD is used to 'autoload' constants from the constant()
  747. # XS function. If a constant is not found then control is passed
  748. # to the AUTOLOAD in AutoLoader.
  749. my($constname);
  750. ($constname = $AUTOLOAD) =~ s/.*:://;
  751. #reset $! to zero to reset any current errors.
  752. $!=0;
  753. $val = constant($constname, @_ ? $_[0] : 0);
  754. if ($! != 0) {
  755. if ($! =~ /Invalid/) {
  756. $AutoLoader::AUTOLOAD = $AUTOLOAD;
  757. goto &AutoLoader::AUTOLOAD;
  758. }
  759. else {
  760. # Added by JOC 06-APR-96
  761. # $pack = 0;
  762. $pack = 0;
  763. ($pack,$file,$line) = caller;
  764. print "Your vendor has not defined Win32::ODBC macro $constname, used in $file at line $line.";
  765. }
  766. }
  767. eval "sub $AUTOLOAD { $val }";
  768. goto &$AUTOLOAD;
  769. }
  770. # --------------------------------------------------------------
  771. #
  772. #
  773. # Make sure that we shutdown ODBC and free memory even if we are
  774. # using perlis.dll on Win32 platform!
  775. END{
  776. # ODBCShutDown() unless $CacheConnection;
  777. }
  778. bootstrap Win32::ODBC;
  779. # Preloaded methods go here.
  780. # Autoload methods go after __END__, and are processed by the autosplit program.
  781. 1;
  782. __END__