home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 10 / ioProg_10.iso / soft / optima / samples.z / ODBCAdmin.wxc < prev    next >
Encoding:
Text File  |  1996-06-12  |  4.8 KB  |  199 lines

  1. Save Format v1.3
  2. @begin ClassFile "ODBCAdmin"
  3.  Exported 0;
  4.  
  5. @begin-code BaseClassList
  6.  
  7. public WObject
  8.  
  9. @end-code;
  10.  
  11.  @begin UserFunction "ODBCAdmin()"
  12.   GencodeSrcLine 15;
  13.   FunctionName "ODBCAdmin::ODBCAdmin()";
  14.  @end;
  15.  
  16.  @begin UserFunction "Prototype for ODBCAdmin()"
  17.   Private 1;
  18.   GencodeSrcLine 26;
  19.   FunctionName "ODBCAdmin::Prototype for ODBCAdmin()";
  20.  @end;
  21.  
  22.  @begin UserFunction "~ODBCAdmin()"
  23.   GencodeSrcLine 19;
  24.   FunctionName "ODBCAdmin::~ODBCAdmin()";
  25.  @end;
  26.  
  27.  @begin UserFunction "Prototype for ~ODBCAdmin()"
  28.   Private 1;
  29.   GencodeSrcLine 28;
  30.   FunctionName "ODBCAdmin::Prototype for ~ODBCAdmin()";
  31.  @end;
  32.  
  33.  @begin UserFunction "DriverExists( const WString& , WString& )"
  34.   GencodeSrcLine 23;
  35.   FunctionName "ODBCAdmin::DriverExists( const WString& , WString& )";
  36.  @end;
  37.  
  38.  @begin UserFunction "Prototype for DriverExists( const WString& , WString& )"
  39.   Private 1;
  40.   GencodeSrcLine 30;
  41.   FunctionName "ODBCAdmin::Prototype for DriverExists( const WString& , WString& )";
  42.  @end;
  43.  
  44.  @begin UserFunction "AddDataSource( const WString &ds_name, const WString &driver_name, const WStringArray &keys )"
  45.  @end;
  46.  
  47.  @begin UserFunction "Prototype for AddDataSource( const WString &ds_name, const WString &driver_name, const WStringArray &keys )"
  48.   Private 1;
  49.   GencodeSrcLine 32;
  50.   FunctionName "ODBCAdmin::Prototype for AddDataSource( const WString &ds_name, const WString &driver_name, const WStringArray &keys )";
  51.  @end;
  52.  
  53.  @begin HPPPrefixBlock
  54. @begin-code HPPPrefix
  55.  
  56. // Declarations added here will be included at the top of the .HPP file
  57.  
  58. @end-code;
  59.   GencodeSrcLine 11;
  60.  @end;
  61.  
  62.  @begin CPPPrefixBlock
  63. @begin-code CPPPrefix
  64.  
  65. // Code added here will be included at the top of the .CPP file
  66.  
  67. //  Include definitions for resources.
  68. #include "WRes.h"
  69.  
  70. @end-code;
  71.   GencodeSrcLine 11;
  72.  @end;
  73.  
  74.  @begin ClassContentsBlock
  75. @begin-code ClassContents
  76.  
  77.   
  78.     public:
  79.         static WBool DriverExists( const WString &driver, WString &driver_dll );
  80.     public:
  81.         static WBool AddDataSource( const WString &ds_name, const WString &driver_name, const WStringArray &keys ); 
  82.  
  83.     private:
  84.         // add your private instance data here
  85.     protected:
  86.         // add your protected instance data here
  87.  
  88. @end-code;
  89.   GencodeSrcLine 16;
  90.  @end;
  91.  
  92. @begin-code GeneratedClassContents
  93.  
  94.  
  95. @end-code;
  96.  
  97. @begin-code Code "ODBCAdmin::ODBCAdmin()"
  98.  
  99. ODBCAdmin::ODBCAdmin()
  100. {
  101.     
  102. }
  103.  
  104. @end-code;
  105.  
  106. @begin-code Code "ODBCAdmin::Prototype for ODBCAdmin()"
  107.  
  108.     public:
  109.         ODBCAdmin();
  110.  
  111. @end-code;
  112.  
  113. @begin-code Code "ODBCAdmin::~ODBCAdmin()"
  114.  
  115. ODBCAdmin::~ODBCAdmin()
  116. {
  117.     
  118. }
  119.  
  120. @end-code;
  121.  
  122. @begin-code Code "ODBCAdmin::Prototype for ~ODBCAdmin()"
  123.  
  124.     public:
  125.         ~ODBCAdmin();
  126.  
  127. @end-code;
  128.  
  129. @begin-code Code "ODBCAdmin::DriverExists( const WString& , WString& )"
  130.  
  131. static WBool ODBCAdmin::DriverExists( const WString& driver, WString& driver_dll)
  132. {
  133.     WRegistryKey        registry;
  134.     WString             key;
  135.     
  136.     key.Clear();
  137.     key.Sprintf( "Software\\ODBC\\ODBCINST.INI\\%s", driver.GetText() );
  138.     if( registry.Open( WRKeyLocalMachine, key ) ) {
  139.         driver_dll = registry.GetStringValue( "Driver" );
  140.         registry.Close();
  141.         if( !driver_dll.GetNull() ) {
  142.             return( TRUE );
  143.         }
  144.     }
  145.  
  146.     return( FALSE );
  147. }
  148.  
  149. static WBool ODBCAdmin::AddDataSource( const WString &ds_name, const WString &driver_name, const WStringArray &keys )
  150. {
  151.     WRegistryKey            registry;
  152.     WString                    key;
  153.     int                     i;
  154.     
  155.     key = "Software\\ODBC\\ODBC.INI\\ODBC Data Sources";
  156.     if( registry.Open( WRKeyCurrentUser, key ) ) {
  157.         if( registry.HasValue( ds_name, WRegDataString ) ) {
  158.             return( TRUE );
  159.         }
  160.     } else {
  161.         return( FALSE );
  162.     }
  163.     
  164.     registry.SetStringValue( ds_name, driver_name );
  165.     registry.Close();
  166.  
  167.     key.Sprintf( "Software\\ODBC\\ODBC.INI\\%s", ds_name.GetText() );
  168.     if( registry.Create( WRKeyCurrentUser, key ) ) {
  169.         for( i = 0; i * 2 < keys.GetCount(); ++i ) {
  170.             registry.SetStringValue( keys[i * 2], keys[i * 2 + 1] );
  171.         }
  172.     }
  173.     registry.Close();
  174.     
  175.     return( TRUE );
  176. }
  177.  
  178. @end-code;
  179.  
  180. @begin-code Code "ODBCAdmin::Prototype for DriverExists( const WString& , WString& )"
  181.  
  182.     public:
  183.         static WBool DriverExists( const WString& , WString& );
  184.  
  185. @end-code;
  186.  
  187. @begin-code Code "ODBCAdmin::AddDataSource( const WString &ds_name, const WString &driver_name, const WStringArray &keys )"
  188.  
  189.  
  190. @end-code;
  191.  
  192. @begin-code Code "ODBCAdmin::Prototype for AddDataSource( const WString &ds_name, const WString &driver_name, const WStringArray &keys )"
  193.  
  194.     public:
  195.         static WBool AddDataSource( const WString &ds_name, const WString &driver_name, const WStringArray &keys );
  196.  
  197. @end-code;
  198. @end;
  199.