3 using System
.Data
.Odbc
;
4 using System
.Collections
.Specialized
;
12 static Ini settings
= new Ini("wvodbc.ini");
14 public Db(string odbcstr
)
18 if (settings
[odbcstr
].Count
> 0)
20 StringDictionary sect
= settings
[odbcstr
];
22 string s
= wv
.fmt("driver={0};server={1};database={2};"
24 sect
["driver"], sect
["server"],
26 sect
["user"], sect
["password"]);
29 else if (String
.Compare(odbcstr
, 0, "dsn=", 0, 4, true) == 0)
31 else if (String
.Compare(odbcstr
, 0, "driver=", 0, 7, true) == 0)
34 throw new ArgumentException
35 ("unrecognized odbc string '" + odbcstr
+ "'");
36 db
= new OdbcConnection(real
);
40 public IDbCommand
prepare(string sql
, int nparams
)
42 IDbCommand cmd
= db
.CreateCommand();
43 cmd
.CommandText
= sql
;
44 for (int i
= 0; i
< nparams
; i
++)
45 cmd
.Parameters
.Add(cmd
.CreateParameter());
50 void bind(IDbCommand cmd
, params object[] args
)
53 foreach (IDataParameter param
in cmd
.Parameters
)
57 param
.DbType
= DbType
.DateTime
;
59 param
.DbType
= DbType
.String
; // I sure hope so...
64 public IDataReader
select(string sql
, params object[] args
)
66 return select(prepare(sql
, args
.Length
), args
);
69 public IDataReader
select(IDbCommand cmd
, params object[] args
)
72 return cmd
.ExecuteReader();
75 public int execute(string sql
, params object[] args
)
77 return execute(prepare(sql
, args
.Length
), args
);
80 public int execute(IDbCommand cmd
, params object[] args
)
83 return cmd
.ExecuteNonQuery();
86 public int try_execute(string sql
, params object[] args
)
90 return execute(sql
, args
);
94 // well, I guess no rows were affected...