Win32 :: ODBC - Object ---------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------- - Creating an ODBC Object Your Script Will Need To Have The Following Line: Use Win32 :: odbc; the you will need to your dsn: $ data = new win32 :: odbc ("mydsn"); you shoud check to see if $ data is indeed defined Otherwise there is, . you can now send SQL queries and retrieve info to your heart's content See the description of functions below and also test.pl to see how it all works Make sure that you close your connection when you are finished:!. $ Data-> Close (); ----------------------------------------------- ------------------------------ --- Back to the top Object Methods General Note All Methods Assume That You Have the line: Use Win32 :: ODBC; Somewhere Before The Method Calls, And That You Have An Odbc Object Called $ DB Which Was Created Using Some Call Similar To: $ db = new win32 :: odbc ("mydsn"); see new fo . R more information Also, in an effort to keep the examples short, no error checking is done on return values for any calls other than the one being exemplified You should always check for error conditions in production code WARNING:.. The example code has not yet been tested. This will be fixed ASAP, but be forwarned! Methods Back to the top Catalog qualifier, owner, name, type Retrieves the catalog from the current ODBC object. Returns a four-element array (qualifier, owner, name, TYPE: All FieldNames Are Uppercase! Example: ($ Qualifier, $ Owner, $ Name, $ TYPE) = $ db-> catalog (",", "%", "'Table');
. Back to the top Connection Returns the object's ODBC connection number Example: $ cnum = $ db-> Connection; Back to the top Close Closes the ODBC connection for this object It always returns undef Example: $ db-> Close ().. ;.. Back to the top Data Data list Retrieve data from previous fetch for a list of field names in a scalar context it returns all of the field values concatenated together in an array context, it returns an array of the values, in the order IN which the were specified. If no field names are given, all fields are returned in an unspect: $ db-> sql ("SELECT F1, F2, F3 from foo"); $ db-> fetchrow (); ($ F1, $ F2) = $ DB-> DATA ("F1", "F2"); or $ db-> SQL ("Select * from foo"); $ dB-> fetchrow (); @Values = $ db-> Data; See also:. DataHash Back to the top DataHash DataHash list Retrieve data from previous fetch for a list of field names Returns a hash where the field name is the key If no field names are given, all fields are returned. EXAMPLE: $ dB-> SQL ("SELECT F1, F2, F3 from foo"); $ db-> fetchrow ();% hash = $ db-> datahash ("f1", "f2"); Print $ hash {f1}; or $ db- > SQL ("Select * from foo"); $ db-> fetchrow ();% hash = $ db-> datahash; foreach $ key (sort (keys% haveh) {print $ key, '=', $ hash {$ key}, "/ n";} See also: Data Back to the top DataSources Returns an associative array of Data Sources and ODBC remarks in the form of: $ ArrayName { 'DSN'} = Remark where DSN is the Data Source Name and remark IS, Well, The Remark. EXAMPLE:% Rem = $ DB-> DataSources; Print Log QQ (Current DSN's Remark:),% Rem {$ DB->
GetDSN}, qq ( "/ n); Back to the top Drivers Returns an associative array of Drivers and their attributes in the form of: $ ArrayName { 'DRIVER'} = Attrib1; Attrib2; Attrib3; ... where DRIVER is the ODBC Driver Name and AttribX are the driver-defined attributes Example:% attrib = $ db-> Drivers; print LOG qq ($ driver: $ attrib {$ driver} / n). foreach $ driver (keys% attrib); Back to the top DumpError Dump to the screen details about the last error condition This includes error number, error text and the ODBC connection number that caused the error (if there is one) This is used primarily for debugging Example:... $ db = new Win32 :: ODBC ("My DSN"); if (undef $ db) {Win32 :: odbc :: Dumperror ();} if ($ db-> sql ("select * from foo") {$ db-> . DumpError;} Back to the top DumpData Dump to the screen all field names and the data in all rows of the current dataset This is used primarily for debugging Example: $ db-> Sql ( "Select * FROM foo"); $. DB-> DUMPDATA; Back to the Top Error Returns the L ast recorded error in the form of an array or string (depending upon the context) containing the error number, error text and the ODBC connection that caused the error (if there is one) Example:. die $ db-> Error (), QQ (/ N); ($ Errnum, $ Errtext, $ Errconn) = $ db-> error (); back to the top fetchrow fetches the next row of data from the prep at specified sql statement. you would the call data or datahash TO ACTUALLY RETA. RETURNS Undef if there's an error: $ db-> sql ("select * from foo"); $ db-> fetchrow () || DIE QQ (Fetch Error: ), $ db-> error (), QQ (/ N); $ f1 = $ db-> data ("f1");
See also: Sql, Data, DataHash Back to the top FieldNames Returns a list of field names extracted from the current dataset This is used mostly for testing / debugging FieldNames returns the data in an array, with no guarantee of the order of the.. Names. EXAMPLE: $ db-> SQL ("Select * from foo"); $ db-> fetchrow (); foreach $ fd ($ db-> fieldnames ()) Print QQ ($ fd: "), $ dB- > Data ($ fd), qq ( "/ n); Back to the top GetConnections Returns an array of connection numbers for all objects Example:. @cnums = $ db-> GetConnections; Back to the top GetDSN GetDSN conn Returns the DSN (Data Source Name) or The Current Conn, or The Current Conn, or The Current Connection If Not Specified. EXAMPLE: Print Log QQ (Current Connection: "), $ DB-> getDSN, QQ (" / n); Back to the top GetMaxBufSize Returns the current maximum single field data size, in bytes Example: $ max = $ db-> GetMaxBufSize; $ db-> SetMaxBufSize ($ needed) if ($ max <$ needed); See also:. SetMaxBufSize Back to the Top getStmtcl . OseType Returns the current ODBC close type setting This is used mainly for debugging Type will be one of:.. SQL_CLOSE, SQL_DROP, SQL_UNBIND, or SQL_RESET_PARAMS See SetStmtCloseType for more info on what each of the types mean, and how they are used. Example: $ oldct = $ db-> GetStmtCloseType; $ db-> SetStmtCloseType (SQL_DROP); ... $ db-> SetStmtCloseType ($ oldct); See also: SetStmtCloseType Back to the top MoreResults Sees if more result sets are present and Initializes for Fetching Rows from Next Result Set. You Would The Call Fetchrow To Actually Fetch The next Ret Row of The Next Result Set. Returns Und Result Set. Returns Und Result Set. Returns Und Result Set. Returns Und Result Set. Returns Und Result Set. Returns Und Result Set. Returns Und Result Set. Returns Und Result Set. Returns UndEf If If If The ANERROR, TRUE OtherWise. EXAMPLE: $ DB->
SQL ("Select * from foo / n select * from bar"); $ db-> fetchrow () || DIE QQ (Fetch Error:), $ db-> error (), qq (/ n); $ f1 = $ db-> data ("f1"); $ db-> moreresults () || DIE QQ (Error Checking for more result sets:), $ db-> error (), qq (/ n); $ db-> Fetchrow () || DIE QQ (Fetch Error:), $ dB-> Error (), QQ (/ N); $ f1 = $ db-> data ("f1"); see Also: SQL, Data Back to the top new Win32 :: ODBC (DSN) new Win32 :: ODBC (oDBCDriverConnect) Creates a new ODBC object, given a DSN (Data Source Name) or a properly formatted oDBCDriverConnect string. Returns the created ODBC object or undef if there is an error EXAMPLE: $ DSN = "MYDSN"; $ db = new win32 :: odbc ($ dsn); DIE QQ (Cannot Open new odbc / n) if! $ Db; or $ db = new Win32 :: ODBC ("DSN = Foo; uid = bar; pwd = fubar "); DIE QQ (Cannot Open new odbc / n) IF! $ Db; back to the top rowcount returns the number of rows what were affected by the prepvious sql command. Note: this Does Not Work On All ODBC Connections. EXAMPLE: $ DB-> SQL ("SELECT * from foo"); Print DBG Q (# of records:), $ DB-> ROWCOUNT (), QQ (/ N); Back to the Top Run Stmt Submit The Sql Statement Stmt and Print Data About It. this is buy @ly in debugging. EXAMPLE: $ db-> run ("SELECT * FROM FOO "); See also: Sql Back to the top SetMaxBufSize size Sets the maximum buffer size that a single field can allocate when executing a fetchRow The default limit is 10240 bytes and the absolute maximum is set to 2147483647 bytes This absolute maximum can be.. Reset by ReCompiling The Module. Returns undeSize = 20480; $ rc = $ db-> setmaxbufsize; Die QQ (SetMaxbufsize ($ newsize) error:), $ db->
! Error, qq (/ n) if $ rc; See also: GetMaxBufSize Back to the top SetStmtCloseType type Sets the current ODBC close type setting used by the ODBC Manager This is used mainly for debugging Normally, when you open a statement handle.. and perform a query (or whatever) the results are associated with the statement. you need to free the statement in order to This caching action may be execute another query. When you do this, usually the dataset (from the query) is cached. good for speed but could cause some memory problems if your dataset is huge. See the ODBC API call SQLFreeStmt (hstmt, option) for more details. (All of this is handled automatically by the Win32 :: ODBC package). Type will be one of: SQL_CLOSE - just close the statement (use caching) SQL_DROP - close and drop all results (do not use caching) SQL_UNBIND - close and remove bindings to columns (odbc.pll does not bind vars to columns) SQL_RESET_PARAMS - close and reset all Of the bound parameters (Such As Type Casting for columns; see SQLFreeStmt ()) Example: $ oldct = $ db-> GetStmtCloseType; $ db-> SetStmtCloseType (SQL_DROP); ... $ db-> SetStmtCloseType ($ oldct); See also: GetStmtCloseType Back to the top ShutDown Closes the ODBC connection and print data about it This is used only in debugging Example:.. $ db-> Shutdown; See also:. Close Back to the top Sql stmt Executes the SQL command stmt Returns undef on success, SQL error code on failure EXAMPLE: $ stmt = "select * from foo"; $ rc = $ db-> SQL ($ STMT); Die QQ (SQL Failed "$ STMT":), $ dB-> Error (), QQ (/ N ) IF $ rc;
See also: Error Back to the top TableList TableList qualifier, owner, name, type Retrieves the list of table names from the current ODBC object using Catalog If not specified, qualifier and owner default to "", name defaults to "%",. And Type Defaults to "'Table'". TableList Returns An Array Of Table Names. Note: All FieldNames Are Uppercase! EXAMPLE: @tables = $ dB-> TableList; See Also: catalog ---------- -------------------------------------------------- ------------------ - back to the top example ------------------------- -------------------------------------------------- --- This page maintined by Joe Casadonte. Please let meiff it feelhing is Wrong or Does Not Make Sense. Send these Or Other Comments to: joc@Netaxs.com.------------ -------------------------------------------------- --------------- --- Win32 :: ODBC Object Documentation Page. Copyright Documentation Page. Copy L. Casadonte Jr. 1996. All Rights Reserved. Coursesy of Roth Consulting. Last Updated 2001.0 9.13