1 // DBHelper.cs : Helper class for executing queries with database.
4 // Sureshkumar T (tsureshkumar@novell.com)
6 // Copyright (c) 2004 Novell Inc., and the individuals listed on the
10 // Permission is hereby granted, free of charge, to any person
11 // obtaining a copy of this software and associated documentation
12 // files (the "Software"), to deal in the Software without
13 // restriction, including without limitation the rights to use, copy,
14 // modify, merge, publish, distribute, sublicense, and/or sell copies
15 // of the Software, and to permit persons to whom the Software is
16 // furnished to do so, subject to the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
25 // BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
26 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27 // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 using System.Data.Common;
35 using System.Data.Odbc;
38 using NUnit.Framework;
40 namespace MonoTests.System.Data
42 public sealed class DBHelper
44 public static Random random = new Random ( (int) DateTime.Now.Ticks);
46 public static int ExecuteNonQuery (IDbConnection connection ,string query)
48 IDbCommand command = connection.CreateCommand ();
49 command.CommandType = CommandType.Text;
50 command.CommandText = query;
53 result = command.ExecuteNonQuery ();
54 } catch (Exception e) {
60 public static int ExecuteSimpleSP (IDbConnection connection ,string proc)
62 IDbCommand command = connection.CreateCommand ();
63 command.CommandType = CommandType.StoredProcedure;
64 command.CommandText = proc;
67 result = command.ExecuteNonQuery ();
68 } catch (Exception e) {
74 public static string GetRandomName (string prefix, int length)
76 StringBuilder s = new StringBuilder (prefix.Length + 1 + length);
79 for (int i = 0; i < length; i++) {
80 s.Append (random.Next (25) + 'A');