+++ /dev/null
-list
-.makefrag
-.response
-library-deps.stamp
+++ /dev/null
-2002-11-13 Daniel Morgan <danmorg@sc.rr.com>
-
- * Mono.Data.MySql/MySqlParameter.cs
- * Mono.Data.MySql/MySqlParameterCollection.cs: added
- simple input parameters support. AFAIK, MySQL does not
- support parameters, so this is just a search and replace
-
- * Test/TestParameters.cs: add file to test Parameters
-
- * Test/TestDataAdapter.cs: add file to test MySqlDataAdapter
-
- * Mono.Data.MySql.build: added files to windows build
-
- * list: added files to linux build
-
- * Mono.Data.MySql/MySql.cs: make sure all
- DllImport attributes
- also have the SuppressUnmanagedCodeSecurity attribute
-
- * Mono.Data.MySql/MySqlCommand.cs: add support for
- input parameters, don't execute empty queries,
- and support of CommandTypes of StoredProcedure and TableDirect
-
- * Mono.Data.MySql/MySqlConnection.cs: borrowed Tim Coleman's
- code from SqlConnection to handle connection
- parameters correctly
-
- * Mono.Data.MySql/MySqlTypes.cs
- * Mono.Data.MySql/MySqlDataReader.cs: started support
- for NULL values.
-
- * Test/MySqlTest.cs: test for NULL values, stored procedures,
- executing a non-query via ExecuteReader(), new connection
- string functionality, and exception handling
-
-2002-11-01 Daniel Morgan <danmorg@sc.rr.com>
-
- * Mono.Data.MySql/MySqlDataAdapter.cs
- * Mono.Data.MySql/MySqlRowUpdatedEventArgs.cs
- * Mono.Data.MySql/MySqlRowUpdatedEventHandler.cs
- * Mono.Data.MySql/MySqlRowUpdatingEventArgs.cs
- * Mono.Data.MySql/MySqlRowUpdatingEventHandler.cs: added new
- files for the Data Adapter for the MySQL data provider
-
- * list: added new files to Linux build
-
- * Mono.Data.MySql/MySqlCommand.cs: implement the
- interfaces correctly and Dispose(). Allow the provider to
- execute multiple queries for a reader
-
- * Mono.Data.MySql/MySqlTransaction.cs
- * Mono.Data.MySql/MySqlConnection.cs: implement the
- interfaces correctly and Dispose
-
- * Mono.Data.MySql/MySqlDataReader.cs: implement the
- interfaces correctly and Dispose(). Allow the provider to
- execute multiple queries for a reader. Implement
- IEnumerable.GetEnumerator() to return a DbEnumerator
- which can be used to do a
- foreach (DbDataRecord rec in myDataReader) { ... }
- and allows a IDataReader to be "data binded" to a DataGrid.
- Thanks goes to Tim Coleman (I copied this from his SqlDataReader).
-
-2002-10-26 Daniel Morgan <danmorg@sc.rr.com>
-
- * Mono.Data.MySql/MySqlError.cs
- * Mono.Data.MySql/MySqlErrorCollection.cs
- * Mono.Data.MySql/MySqlException.cs: added files for
- MySQL Exceptions
-
- * Mono.Data.MySql.build: removed excludes for new
- files (thus adding them to the build) on Windows
-
- * list: added files to build on Linux
-
- * Mono.Data.MySql/MySqlCommand.cs
- * Mono.Data.MySql/MySqlConnection.cs: modified
- to throw a new MySqlException when a MySqlError occurs
-
-2002-10-13 Daniel Morgan <danmorg@sc.rr.com>
-
- * Mono.Data.MySql/MySqlDataReader.cs: change "DataType" in
- schema DataTable to be typeof(Type) instead of
- typeof(string) to make it more like MS.NET
-
- * Test/MySqlTest.cs: tweaks
-
-2002-10-13 Daniel Morgan <danmorg@sc.rr.com>
-
- * Mono.Data.MySql/MySqlCommand.cs:
- * Mono.Data.MySql/MySqlConnection.cs:
- * Mono.Data.MySql/MySqlDataReader.cs:
- * Mono.Data.MySql/MySqlTypes.cs: modifed -
- handle MySQL types to .NET types and some fixes
-
-2002-10-12 Daniel Morgan <danmorg@sc.rr.com>
-
- * Test/MySqlTest.cs: added file - to do
- various Tests for the MySql provider
-
- * Mono.Data.MySql/Field.cs: enum MySqlFieldFlags
- should be unit. Rename class Field to MySqlMarshalledField
- to represent what it really is. Redo handling of field Flags.
-
- * Mono.Data.MySql/MySql.cs: added method AffectedRows() to
- pinvoke into mysql_affected_rows() so we can know what rows
- were affected by an INSERT, UPDATE, or DELETE SQL statement.
-
- * Mono.Data.MySql/MySqlCommand.cs: rename
- internal method rowVal() to GetColumnData(). In GetColumnData,
- if IntPtr.Zero, return an empty "" string instead of "NULL".
- Pass command behavior to data reader.
-
- * Mono.Data.MySql/MySqlDataReader.cs: redo the
- way field meta data and data is structured so
- a schema DataTable can be built. Implement
- GetSchemaTable() to create a DataTable holding the schema
- of the fields. Implemented more methods.
-
- * Mono.Data.MySql/MySqlTypes.cs: added method to
- translate System.Data.DbType to System.Type
-
- * est/TestMySqlExecuteReader.cs: minor tweaks
-
-2002-10-11 Daniel Morgan <danmorg@sc.rr.com>
-
- * Mono.Data.MySql/MySqlTransaction.cs: added to
- support transactions (BEGIN, COMMIT/ROLLBACK).
-
- * Mono.Data.MySql.build: included MySqlTransaction
- in build on Windows
-
- * list: included MySqlTransaction
- in build on Linux
-
- * Mono.Data.MySql/MySql.cs: the mysql thread functions
- were misnamed and prevented them from being loaded
- by the mono JIT - my_thread_init() and my_thread_end().
- Now, threading should work in the MySQL provider and
- less memory leaks too.
-
- * Mono.Data.MySql/Test.cs: remove conditional comiliation
- since everything compiles fine on Mono now
-
- * Mono.Data.MySql/MySqlCommand.cs: remove Console.WriteLine()
-
- * Mono.Data.MySql/MySqlConnection.cs: added transaction
- support, implemented method ChangeDatabase(), implemented
- property ServerVersion
-
- * Test/TestMySqlInsert.cs: modified test
- to handle transactions
-
-2002-10-10 Rodrigo Moya <rodrigo@ximian.com>
-
- * makefile.gnu: added makefile for linux build.
-
- * list: updated to contain all missing files.
-
- * Mono.Data.MySql/makefile: removed unneeded makefile.
-
-2002-10-09 Daniel Morgan <danmorg@sc.rr.com>
-
- * Mono.Data.MySql/MySqlDataReader.cs: added
- started implementing Reader for MySQL provider
-
- * Mono.Data.MySql/MySqlTypes.cs: added
- to hold internal helper methods, enums, structs, classes
- for handling MySQL data types
-
- * Test/TestMySqlExecuteReader.cs
- * Test/TestMySqlExecuteScalar.cs: added simple tests
- for ExecuteScalar() and ExecuteReader() methods
- in MySqlCommand. We are able to retrieve data
- from MySQL now.
-
- * Mono.Data.MySql.build: took out exclude
- so MySqlExecuteReader.cs will build
-
- * Mono.Data.MySql/Field.cs: added enum to file
- and added helper methods field flags
-
- * Mono.Data.MySql/MySqlCommand.cs: started
- implementation of ExecuteScalar nd ExecuteReader methods
- to retrieve data. Also, added internal method rowVal
- for marshalling field data.
-
- * Mono.Data.MySql/Test.cs: take out a bunch of
- Console.WriteLines'
-
-2002-08-13 Daniel Morgan <danmorg@sc.rr.com>
-
- * Mono.Data.MySql/MySqlCommand.cs: modified
- rowsRetrieved should be rowsAffected in ExecuteNonQuery
- because the number is only to show the rows affected
- by an INSERT, UPDATE, or DELETE; anything else, the
- number is -1
-
- * Mono.Data.MySql/Test.cs: modified
- enable retrieving the results from a query. even though
- this still does not work for some reason, i thought
- i would enable it so others could see the problem.
-
-2002-05-30 Daniel Morgan <danmorg@sc.rr.com>
-
- * Mono.Data.MySql.build: modified
- need to copy Mono.Data.MySql.dll to mcs/class/System.Data/Test
- so the SqlSharpCli test program can use MySql too
-
-2002-05-30 Daniel Morgan <danmorg@sc.rr.com>
-
- * Test/TestMySqlInsert.cs: added test
- to do an SQL INSERT to insert a row into table.
- Works on cygwin compiled using mcs and mono and
- runs on mint, but it fails running on mono.
-
- * Mono.Data.MySql/MySqlCommand.cs
- * Mono.Data.MySql/TODOAttribute.cs
- * Mono.Data.MySql/MySqlConnection.cs: added
-
- * list: added
- so can build with mcs/mono on linux
- I only tested it on Cygwin though.
- To work on linux, the library name in the pinvokes
- in MySql.cs will need to be changed.
-
- * Mono.Data.MySql.build: modified
- exclude files from build. also copy Mono.Data.MySql.dll
- to Mono.Data.MySql so you can build and run Test.cs
-
- * Mono.Data.MySql/MySql.cs: modified
- tweaks to compile under mcs/mono and run under mint or mono.
- Runs under mint, but not mono. Had to comment out
- mysql_thread_begin/mysql_thread_end functions because they refused
- to load in mono. Until this is fixed, a memory leak will occur.
- Can not retrieve field data from MySQL because the PtrToStructure()
- needs to be implemented in System.Runtime.InteropServices.Marshal class.
- However, this will be very complicated to do. So, we connect to
- MySQL and execute SQL Commands, but we can not do Queries yet.
-
- * Mono.Data.MySql/Test.cs: modified
- tweaks to test C# bindings with compiling mcs/mono and
- running on mint and mono. Runs on mint, but not mono.
-
-2002-05-28 Daniel Morgan <danmorg@sc.rr.com>
-
- * Mono.Data.MySql
- * Mono.Data.MySql/Mono.Data.MySql: add directories
- for the Mono.Data.MySql assembly and namespace. This
- will contain the MySql .NET Data Provider which will use
- C# bindings to libMySQL
-
- * Mono.Data.MySql/Test.cs: added file to
- test the C# bindings to MySQL
-
- * Mono.Data.MySql/MySql.cs
- * Mono.Data.MySql/Field.cs: added files
- for the beginnings of C# bindings to MySQL
-
- * Mono.Data.MySql/makefile: added file
- to build the MySQL C# bindings on csc/Microsoft.NET
-
- These C# bindings to the MySQL libMySQL.dll were created by
- Brad Merrill <zbrad@cybercom.net>
- and can be downloaded from
- http://www.cybercom.net/~zbrad/DotNet/MySql/
- and put into the Mono Class Library under the X11/MIT License
- with Brad Merril's permission.
-
+++ /dev/null
-thisdir = class/Mono.Data.MySql
-SUBDIRS =
-include ../../build/rules.make
-
-LIBRARY = Mono.Data.MySql.dll
-LIB_MCS_FLAGS = /r:$(corlib) /r:System.dll /r:System.Xml.dll /r:System.Data.dll
-NO_TEST = yes
-
-EXTRA_DISTFILES = \
- Test/MySqlTest.cs \
- Test/TestDataAdapter.cs \
- Test/TestMySqlExecuteReader.cs \
- Test/TestMySqlExecuteScalar.cs \
- Test/TestMySqlInsert.cs \
- Test/TestParameters.cs
-
-include ../../build/library.make
+++ /dev/null
-Mono.Data.MySql/Field.cs
-Mono.Data.MySql/MySqlCommand.cs
-Mono.Data.MySql/MySqlConnection.cs
-Mono.Data.MySql/MySql.cs
-Mono.Data.MySql/TODOAttribute.cs
-Mono.Data.MySql/MySqlDataReader.cs
-Mono.Data.MySql/MySqlTypes.cs
-Mono.Data.MySql/MySqlTransaction.cs
-Mono.Data.MySql/MySqlError.cs
-Mono.Data.MySql/MySqlErrorCollection.cs
-Mono.Data.MySql/MySqlException.cs
-Mono.Data.MySql/MySqlDataAdapter.cs
-Mono.Data.MySql/MySqlRowUpdatedEventArgs.cs
-Mono.Data.MySql/MySqlRowUpdatedEventHandler.cs
-Mono.Data.MySql/MySqlRowUpdatingEventArgs.cs
-Mono.Data.MySql/MySqlRowUpdatingEventHandler.cs
-Mono.Data.MySql/MySqlParameter.cs
-Mono.Data.MySql/MySqlParameterCollection.cs
-
+++ /dev/null
-//
-// Field.cs
-//
-// Provide definition for the Field class
-// Part of the C# bindings to MySQL library libMySQL.dll
-//
-// Author:
-// Brad Merrill <zbrad@cybercom.net>
-// Daniel Morgan <danmorg@sc.rr.com>
-//
-// (C)Copyright 2002 Brad Merril
-// (C)Copyright 2002 Daniel Morgan
-//
-// http://www.cybercom.net/~zbrad/DotNet/MySql/
-//
-// Mono has gotten permission from Brad Merrill to include in
-// the Mono Class Library
-// his C# bindings to MySQL under the X11 License
-//
-// Mono can be found at http://www.go-mono.com/
-// The X11/MIT License can be found
-// at http://www.opensource.org/licenses/mit-license.html
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-
-namespace Mono.Data.MySql {
- using System;
- using System.Runtime.InteropServices;
-
- [Flags]
- internal enum MySqlFieldFlags : uint {
- NOT_NULL_FLAG = 1,
- PRI_KEY_FLAG = 2,
- UNIQUE_KEY_FLAG = 4,
- MULTIPLE_KEY_FLAG = 8,
- BLOB_FLAG = 16,
- UNSIGNED_FLAG = 32,
- ZEROFILL_FLAG = 64,
- BINARY_FLAG = 128,
- ENUM_FLAG = 256,
- AUTO_INCREMENT_FLAG = 512,
- TIMESTAMP_FLAG = 1024,
- SET_FLAG = 2048,
- NUM_FLAG = 32768,
- PART_KEY_FLAG = 16384,
- GROUP_FLAG = 32768,
- UNIQUE_FLAG = 65536
- }
-
- ///<remarks>
- ///<para>
- /// MySql P/Invoke implementation test program
- /// Brad Merrill
- /// 3-Mar-2002
- ///</para>
- ///<para>
- /// This structure contains information about a field, such as the
- /// field's name, type, and size. Its members are described in more
- /// detail below. You may obtain the <see cref="Field"/> structures for
- /// each field by calling
- /// <see cref="MySql.FetchField"/>
- /// repeatedly.
- /// Field values are not part of this structure;
- /// they are contained in a Row structure.
- ///</para>
- ///</remarks>
- [StructLayout(LayoutKind.Sequential)]
- public class MySqlMarshalledField {
-
- ///<value>name of column</value>
- [MarshalAs(UnmanagedType.LPStr)]
- public string Name;
- ///<value>table of column</value>
- [MarshalAs(UnmanagedType.LPStr)]
- public string Table;
- ///<value>default value</value>
- [MarshalAs(UnmanagedType.LPStr)]
- public string Def;
- ///<value>type of field</value>
- public int FieldType;
- ///<value>width of column</value>
- public uint Length;
- ///<value>max width of selected set</value>
- public uint MaxLength;
- ///<value>div flags</value>
- public uint Flags;
- ///<value>number of decimals in field</value>
- public uint Decimals;
- }
-
- internal sealed class MySqlFieldHelper {
-
- public static bool IsPrimaryKey(uint fieldFlags) {
- // if ((SomeEnum)U & SomeEnum.EnumFlagValue) != 0) {...}
- if(! (((MySqlFieldFlags) fieldFlags) & MySqlFieldFlags.PRI_KEY_FLAG).Equals(0))
- return true;
- else
- return false;
- }
-
- public static bool IsNotNull(uint fieldFlags) {
-
- if(! (((MySqlFieldFlags) fieldFlags) & MySqlFieldFlags.NOT_NULL_FLAG).Equals(0))
- return true;
- else
- return false;
- }
-
- public static bool IsBlob(uint fieldFlags) {
-
- if(! (((MySqlFieldFlags) fieldFlags) & MySqlFieldFlags.BLOB_FLAG).Equals(0))
- return true;
- else
- return false;
- }
- }
-}
+++ /dev/null
-//
-// MySql.cs
-//
-// Provides the core of C# bindings
-// to the MySQL library libMySQL.dll
-//
-// Author:
-// Brad Merrill <zbrad@cybercom.net>
-// Daniel Morgan <danmorg@sc.rr.com>
-//
-// (C)Copyright 2002 Brad Merril
-// (C)Copyright 2002 Daniel Morgan
-//
-// http://www.cybercom.net/~zbrad/DotNet/MySql/
-//
-// Mono has gotten permission from Brad Merrill to include in
-// the Mono Class Library
-// his C# bindings to MySQL under the X11 License
-//
-// Mono can be found at http://www.go-mono.com/
-// The X11/MIT License can be found
-// at http://www.opensource.org/licenses/mit-license.html
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-namespace Mono.Data.MySql {
- using System;
- using System.Security;
- using System.Runtime.InteropServices;
-
- internal sealed class MySql {
- ///<value>protocol version</value>
- public static readonly uint ProtocolVersion = 10;
- ///<value>server version</value>
- public static readonly string ServerVersion = "3.23.49";
- ///<value>server suffix</value>
- public static readonly string ServerSuffix = "";
- ///<value>server version as int</value>
- public static readonly uint VersionId = 32349;
- ///<value>server port number</value>
- public static readonly uint Port = 3306;
- ///<value>unix named socket</value>
- public static readonly string UnixAddr = "/tmp/mysql.sock";
- ///<value>character set</value>
- public static readonly string CharSet = "latin1";
-
- ///<summary>Gets or initializes a `MySql' structure</summary>
- ///<returns>An initialized `MYSQL*' handle. IntPtr.Zero if there was insufficient memory to allocate a new object.</returns>
- [SuppressUnmanagedCodeSecurity]
- [DllImport("libmySQL", EntryPoint="mysql_init", ExactSpelling=true)]
- public static extern IntPtr Init(IntPtr db);
-
- [SuppressUnmanagedCodeSecurity]
- [DllImport("libmySQL", EntryPoint="mysql_affected_rows", ExactSpelling=true)]
- public static extern ulong AffectedRows(IntPtr db);
- //my_ulonglong mysql_affected_rows(MYSQL *mysql);\r
-
- ///<summary>Connects to a MySql server</summary>
- ///<returns><paramref name="db"/> value on success, else returns IntPtr.Zero</returns>
- [SuppressUnmanagedCodeSecurity]
- [DllImport("libmySQL",
- CharSet=System.Runtime.InteropServices.CharSet.Ansi,
- EntryPoint="mysql_connect", ExactSpelling=true)]
- public static extern IntPtr Connect(IntPtr db,
- [In] string host, [In] string user, [In] string passwd,
- [In] string dbname,
- uint port, [In] string socketName, uint flags
- );
-
- ///<summary>Selects a database</summary>
- ///<returns>Zero for success. Non-zero if an error occurred.</returns>
- [SuppressUnmanagedCodeSecurity]
- [DllImport("libmySQL",
- CharSet=System.Runtime.InteropServices.CharSet.Ansi,
- EntryPoint="mysql_select_db", ExactSpelling=true)]
- public static extern int SelectDb(IntPtr conn, [In] string db);
-
- ///<summary>Closes a server connection</summary>
- //[SuppressUnmanagedCodeSecurity]
- [DllImport("libmySQL", EntryPoint="mysql_close", ExactSpelling=true)]
- public static extern void Close(IntPtr db);
-
- ///<summary>Executes a SQL query specified as a string</summary>
- ///<returns>number of rows changed, -1 if zero</returns>
- [SuppressUnmanagedCodeSecurity]
- [DllImport("libmySQL",
- CharSet=System.Runtime.InteropServices.CharSet.Ansi,
- EntryPoint="mysql_query", ExactSpelling=true)]
- public static extern int Query(IntPtr conn, [In] string query);
-
- ///<summary>Retrieves a complete result set to the client</summary>
- ///<returns>An IntPtr result structure with the results. IntPtr.Zero if an error occurred.</returns>
- [SuppressUnmanagedCodeSecurity]
- [DllImport("libmySQL",
- EntryPoint="mysql_store_result", ExactSpelling=true)]
- public static extern IntPtr StoreResult(IntPtr conn);
-
- ///<returns>Returns the number of rows in a result set</returns>
- [SuppressUnmanagedCodeSecurity]
- [DllImport("libmySQL",
- EntryPoint="mysql_num_rows", ExactSpelling=true)]
- public static extern int NumRows(IntPtr r);
-
- ///<returns>Returns the number of columns in a result set</returns>
- [SuppressUnmanagedCodeSecurity]
- [DllImport("libmySQL",
- EntryPoint="mysql_num_fields", ExactSpelling=true)]
- public static extern int NumFields(IntPtr r);
-
- ///<returns>Returns an IntPtr to all field structures</returns>
- [SuppressUnmanagedCodeSecurity]
- [DllImport("libmySQL",
- EntryPoint="mysql_fetch_field", ExactSpelling=true)]
- public static extern IntPtr FetchField(IntPtr r);
-
- ///<summary>Retrieves the next row of a result set</summary>
- ///<returns>An IntPtr structure for the next row. IntPtr.Zero if there are no more rows to retrieve or if an error occurred.</returns>
- [SuppressUnmanagedCodeSecurity]
- [DllImport("libmySQL",
- EntryPoint="mysql_fetch_row", ExactSpelling=true)]
- public static extern IntPtr FetchRow(IntPtr r);
-
- ///<summary>Frees the memory allocated for a result set by <see cref="StoreResult"/></summary>
- [SuppressUnmanagedCodeSecurity]
- [DllImport("libmySQL",
- EntryPoint="mysql_free_result", ExactSpelling=true)]
- public static extern void FreeResult(IntPtr r);
-
- ///<returns>Returns a string that represents the client library version</returns>
- [SuppressUnmanagedCodeSecurity]
- [DllImport("libmySQL",
- CharSet=System.Runtime.InteropServices.CharSet.Ansi,
- EntryPoint="mysql_get_client_info", ExactSpelling=true)]
- public static extern string GetClientInfo();
-
- ///<returns></returns>
- [SuppressUnmanagedCodeSecurity]
- [DllImport("libmySQL",
- CharSet=System.Runtime.InteropServices.CharSet.Ansi,
- EntryPoint="mysql_get_host_info", ExactSpelling=true)]
- public static extern string GetHostInfo(IntPtr db);
-
- ///<returns>A string describing the type of connection in use, including the server host name.</returns>
- [SuppressUnmanagedCodeSecurity]
- [DllImport("libmySQL",
- CharSet=System.Runtime.InteropServices.CharSet.Ansi,
- EntryPoint="mysql_get_server_info", ExactSpelling=true)]
- public static extern string GetServerInfo(IntPtr db);
-
- ///<returns>A string describing the server status. null if an error occurred.</returns>
- [SuppressUnmanagedCodeSecurity]
- [DllImport("libmySQL",
- CharSet=System.Runtime.InteropServices.CharSet.Ansi,
- EntryPoint="mysql_stat", ExactSpelling=true)]
- public static extern string Stat(IntPtr db);
-
- ///<summary>
- /// Returns a result set describing the current server
- /// threads. This is the same kind of information as that
- /// reported by `mysqladmin processlist' or a `SHOW PROCESSLIST'
- /// query. You must free the result set with
- /// <see cref="FreeResult"/>.
- ///</summary>
- ///<returns>
- /// A IntPtr result set for success. IntPtr.Zero if an error
- /// occurred.
- ///</returns>
- [SuppressUnmanagedCodeSecurity]
- [DllImport("libmySQL",
- EntryPoint="mysql_list_processes", ExactSpelling=true)]
- public static extern IntPtr ListProcesses(IntPtr db);
-
- ///<summary>
- ///<para>
- /// Returns a result set consisting of table names in
- /// the current database that match the simple regular expression
- /// specified by the <paramref name="wild"/> parameter.
- /// <paramref name="wild"/>may contain the wild-card characters
- /// "%" or "_", or may be a null pointer to match all tables.
- ///</para>
- ///<para>
- /// Calling <see cref="ListTables"/> is similar to executing
- /// the query "SHOW tables [LIKE wild]".
- ///</para>
- ///<para>
- /// You must free the result set with <see cref="FreeResult"/>.
- ///</para>
- ///</summary>
- [SuppressUnmanagedCodeSecurity]
- [DllImport("libmySQL",
- EntryPoint="mysql_list_tables", ExactSpelling=true)]
- public static extern IntPtr ListTables(IntPtr db, [In] string wild);
-
- ///<summary>
- /// For the connection specified by <paramref name="db"/>,
- /// <see cref="Error"/> returns the
- /// error message for the most recently invoked API function
- /// that can succeed or fail. An empty string ("") is
- /// returned if no error occurred.
- ///</summary>
- ///<returns>
- /// A string that describes the error. An empty string if no error occurred.
- ///</returns>
- [SuppressUnmanagedCodeSecurity]
- [DllImport("libmySQL",
- CharSet=System.Runtime.InteropServices.CharSet.Ansi,
- EntryPoint="mysql_error", ExactSpelling=true)]
- public static extern string Error(IntPtr db);
-
- ///<summary>
- ///<para>
- /// This function needs to be called before exiting
- /// to free memory allocated explicitly by
- /// <see cref="ThreadInit"/> or implicitly by
- /// <see cref="Init"/>.
- ///</para>
- ///<para>
- /// Note that this function is NOT invoked automatically by the client
- /// library!
- ///</para>
- ///</summary>
- [SuppressUnmanagedCodeSecurity]
- [DllImport("libmySQL",
- CharSet=System.Runtime.InteropServices.CharSet.Ansi,
- EntryPoint="my_thread_end", ExactSpelling=true)]
- public static extern void ThreadEnd();
-
- ///<summary>
- ///<para>
- /// This function needs to be called for each created thread
- /// to initialize thread specific variables.
- ///</para>
- ///<para>
- /// This is automatically called by <see cref="Init"/>.
- ///</para>
- ///</summary>
- [SuppressUnmanagedCodeSecurity]
- [DllImport("libmySQL",
- CharSet=System.Runtime.InteropServices.CharSet.Ansi,
- EntryPoint="my_thread_init", ExactSpelling=true)]
- public static extern void ThreadInit();
- }
-}
+++ /dev/null
-//
-// Mono.Data.MySql.MySqlCommand.cs
-//
-// Author:
-// Daniel Morgan (danmorg@sc.rr.com)
-//
-// (C) Daniel Morgan, 2002
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Collections;
-using System.ComponentModel;
-using System.Data;
-using System.Data.Common;
-using System.Runtime.InteropServices;
-using System.Text;
-using System.Xml;
-
-namespace Mono.Data.MySql {
- public sealed class MySqlCommand : Component, IDbCommand, ICloneable {
-
- #region Fields
-
- private string sql = "";
- private int timeout = 30;
- // default is 30 seconds
- // for command execution
-
- private MySqlConnection conn = null;
- private MySqlTransaction trans = null;
- private CommandType cmdType = CommandType.Text;
- private bool designTime = false;
- private MySqlParameterCollection parmCollection = new
- MySqlParameterCollection();
-
- // MySqlDataReader state data for ExecuteReader()
- //private MySqlDataReader dataReader = null;
- private string[] commands = null;
- private int currentQuery = -1;
- private CommandBehavior cmdBehavior = CommandBehavior.Default;
-
- private bool disposed = false;
-
- private const char bindChar = ':';
-
- #endregion // Fields
-
- #region Constructors
-
- public MySqlCommand() {
- sql = "";
- }
-
- public MySqlCommand (string cmdText) {
- sql = cmdText;
- }
-
- public MySqlCommand (string cmdText, MySqlConnection connection) {
- sql = cmdText;
- conn = connection;
- }
-
- public MySqlCommand (string cmdText, MySqlConnection connection,
- MySqlTransaction transaction) {
- sql = cmdText;
- conn = connection;
- trans = transaction;
- }
-
- #endregion // Constructors
-
- #region Methods
-
- [MonoTODO]
- public void Cancel () {
- // FIXME: use non-blocking Exec for this
- throw new NotImplementedException ();
- }
-
- // FIXME: is this the correct way to return a stronger type?
- [MonoTODO]
- IDbDataParameter IDbCommand.CreateParameter () {
- return CreateParameter ();
- }
-
- [MonoTODO]
- public MySqlParameter CreateParameter () {
- return new MySqlParameter ();
- }
-
- public int ExecuteNonQuery () {
- int rowsAffected = -1;
-
- IntPtr res = ExecuteSQL (sql);
-
- if(res.Equals(IntPtr.Zero)) {
- // no result set returned, get records affected
- rowsAffected = (int) MySql.AffectedRows(conn.NativeMySqlInitStruct);
- }
-
- MySql.FreeResult(res);
- res = IntPtr.Zero;
-
- // >= 0 of the number of rows affected by
- // INSERT, UPDATE, DELETE
- // otherwise, -1
- return rowsAffected;
- }
-
- [MonoTODO]
- IDataReader IDbCommand.ExecuteReader () {
- return ExecuteReader ();
- }
-
- [MonoTODO]
- public MySqlDataReader ExecuteReader () {
- return ExecuteReader(CommandBehavior.Default);
- }
-
- [MonoTODO]
- IDataReader IDbCommand.ExecuteReader (
- CommandBehavior behavior) {
-
- return ExecuteReader (behavior);
- }
-
- [MonoTODO]
- public MySqlDataReader ExecuteReader (CommandBehavior behavior) {
-
- MySqlDataReader reader = null;
-
- currentQuery = -1;
-
- commands = sql.Split(new Char[] {';'});
- reader = new MySqlDataReader(this, behavior);
- reader.NextResult();
-
- return reader;
- }
-
- // called by an MySqlDataReader's NextResult()
- internal IntPtr NextResult (out bool result) {
-
- IntPtr mysqlResult = IntPtr.Zero;
- result = false;
-
- currentQuery++;
- if(currentQuery < commands.Length) {
- string query = "";
-
- // don't execute empty queries
- while((query = commands[currentQuery]).Equals("")) {
- currentQuery++;
- if(currentQuery >= commands.Length)
- return IntPtr.Zero;
- }
- mysqlResult = ExecuteSQL (query);
- result = true; // has result
- }
-
- return mysqlResult;
- }
-
- public object ExecuteScalar () {
-
- object obj = null;
-
- IntPtr res = ExecuteSQL (sql);
-
- int numRows = MySql.NumRows(res);
- int numFields = MySql.NumFields(res);
-
- MySqlMarshalledField fd;
- fd = (MySqlMarshalledField) Marshal.PtrToStructure(MySql.FetchField(res),
- typeof(MySqlMarshalledField));
- string fieldName = fd.Name;
- int fieldType = fd.FieldType;
- MySqlEnumFieldTypes mysqlFieldType = (MySqlEnumFieldTypes) fieldType;
- DbType fieldDbType = MySqlHelper.MySqlTypeToDbType(mysqlFieldType);
-
- IntPtr row;
- row = MySql.FetchRow(res);
- if(row == IntPtr.Zero) {
- // EOF
- obj = null;
- }
- else {
- // only get first column/first row
- string objValue = GetColumnData(row, 0);
- obj = MySqlHelper.ConvertDbTypeToSystem (mysqlFieldType, fieldDbType, objValue);
- row = IntPtr.Zero;
- }
- MySql.FreeResult(res);
- res = IntPtr.Zero;
-
- return obj;
- }
-
- // command: string in - SQL command
- // IntPtr (MySqlResult) return - the result
- // Use of this function needs to check to see if
- // if the return equal to IntPtr.Zero
- // Example: IntPtr res = ExecuteSQL ("SELECT * FROM DB");
- // if (res == IntPtr.Zero) { // do something }
- //
- internal IntPtr ExecuteSQL (string command) {
- string msg = "";
-
- if (conn == null)
- throw new InvalidOperationException(
- "Connection is null");
-
- if (conn.State != ConnectionState.Open)
- throw new InvalidOperationException(
- "ConnectionState is not Open");
-
- if (sql.Equals (String.Empty))
- throw new InvalidOperationException(
- "CommandText is Empty");
-
- string query = TweakQuery(sql);
-
- int rcq = MySql.Query(conn.NativeMySqlInitStruct, query);
- if (rcq != 0) {
- msg =
- "MySql Error: " +
- "Could not execute command [" +
- sql +
- "] on server because: " +
- MySql.Error(conn.NativeMySqlInitStruct);
- throw new MySqlException(msg);
- }
- IntPtr result = MySql.StoreResult(conn.NativeMySqlInitStruct);
- return result;
- }
-
- string TweakQuery(string query) {
- string statement = "";
-
- switch(cmdType) {
- case CommandType.Text:
- statement = ReplaceParameterPlaceholders (query);
- break;
- case CommandType.StoredProcedure:
- string sParmList = GetStoredProcParmList ();
- statement = "SELECT " + query + "(" + sParmList + ")";
- break;
- case CommandType.TableDirect:
- statement =
- "SELECT * FROM " + query;
- break;
- }
- return statement;
- }
-
- string GetStoredProcParmList () {
- StringBuilder s = new StringBuilder();
-
- int addedCount = 0;
- for(int p = 0; p < parmCollection.Count; p++) {
- MySqlParameter prm = parmCollection[p];
- if(prm.Direction == ParameterDirection.Input) {\r
- string strObj = MySqlHelper.\r
- ObjectToString(prm.DbType, \r
- prm.Value);\r
- if(addedCount > 0)\r
- s.Append(",");\r
- s.Append(strObj);\r
- addedCount++;\r
- }
- }
- return s.ToString();
- }
-
- // TODO: this only supports input parameters,
- // need support for output, input/output,
- // and return parameters
- // As far as I know, MySQL does not support
- // parameters so the parameters support in this
- // provider is just a search and replace.
- string ReplaceParameterPlaceholders (string query) {\r
- \r
- string resultSql = "";\r
-\r
- StringBuilder result = new StringBuilder();\r
- char[] chars = sql.ToCharArray();\r
- bool bStringConstFound = false;\r
-\r
- for(int i = 0; i < chars.Length; i++) {\r
- if(chars[i] == '\'') {\r
- if(bStringConstFound == true)\r
- bStringConstFound = false;\r
- else\r
- bStringConstFound = true;\r
-\r
- result.Append(chars[i]);\r
- }\r
- else if(chars[i] == bindChar && \r
- bStringConstFound == false) {\r
-\r
- StringBuilder parm = new StringBuilder();\r
- i++;\r
- while(i <= chars.Length) {\r
- char ch;\r
- if(i == chars.Length)\r
- ch = ' '; // a space\r
- else\r
- ch = chars[i];\r
-\r
- if(Char.IsLetterOrDigit(ch)) {\r
- parm.Append(ch);\r
- }\r
- else {\r
- string p = parm.ToString();\r
- bool found = BindReplace(result, p);\r
-\r
- if(found == true)\r
- break;\r
- else { \r
- // *** Error Handling\r
- Console.WriteLine("Error: parameter not found: " + p);\r
- return "";\r
- }\r
- }\r
- i++;\r
- }\r
- i--;\r
- }\r
- else \r
- result.Append(chars[i]);\r
- }\r
- \r
- resultSql = result.ToString();\r
- return resultSql;\r
- }\r
-\r
- bool BindReplace (StringBuilder result, string p) {\r
- // bind variable\r
- bool found = false;\r
-\r
- if(parmCollection.Contains(p) == true) {\r
- // parameter found\r
- MySqlParameter prm = parmCollection[p];\r
-\r
- // convert object to string and place\r
- // into SQL\r
- if(prm.Direction == ParameterDirection.Input) {\r
- string strObj = MySqlHelper.\r
- ObjectToString(prm.DbType, \r
- prm.Value);\r
- result.Append(strObj);\r
- }\r
- else\r
- result.Append(bindChar + p);\r
-\r
- found = true;\r
- }\r
- return found;\r
- }
-
- [MonoTODO]
- public XmlReader ExecuteXmlReader () {
- //MySqlDataReader dataReader = ExecuteReader ();
- //MySqlXmlTextReader textReader = new MySqlXmlTextReader (dataReader);
- //XmlReader xmlReader = new XmlTextReader (textReader);
- //return xmlReader;
- throw new NotImplementedException ();
- }
-
- [MonoTODO]
- public void Prepare () {
- // FIXME: parameters have to be implemented for this
- throw new NotImplementedException ();
- }
-
- object ICloneable.Clone() {
- throw new NotImplementedException ();
- }
-
- // Used to marshal a field value from the database result set.
- // The indexed column data on the current result set row.
- // res = the result set from a MySql.Query().
- // index = the column index.
- internal string GetColumnData(IntPtr res, int index) {
- IntPtr str = Marshal.ReadIntPtr(res, index*IntPtr.Size);
- if (str == IntPtr.Zero)
- return "";
- string s = Marshal.PtrToStringAnsi(str);
- return s;
- }
-
- #endregion // Methods
-
- #region Properties
-
- public string CommandText {
- get {
- return sql;
- }
-
- set {
- sql = value;
- }
- }
-
- public int CommandTimeout {
- get {
- return timeout;
- }
-
- set {
- // FIXME: if value < 0, throw
- // ArgumentException
- // if (value < 0)
- // throw ArgumentException;
- timeout = value;
- }
- }
-
- public CommandType CommandType {
- get {
- return cmdType;
- }
-
- set {
- cmdType = value;
- }
- }
-
- IDbConnection IDbCommand.Connection {
- get {
- return Connection;
- }
-
- set {
- // FIXME: throw an InvalidOperationException
- // if the change was during a
- // transaction in progress
-
- // csc
- Connection = (MySqlConnection) value;
- // mcs
- // Connection = value;
-
- // FIXME: set Transaction property to null
- }
- }
-
- public MySqlConnection Connection {
- get {
- // conn defaults to null
- return conn;
- }
-
- set {
- // FIXME: throw an InvalidOperationException
- // if the change was during
- // a transaction in progress
- conn = value;
- // FIXME: set Transaction property to null
- }
- }
-
- public bool DesignTimeVisible {
- get {
- return designTime;
- }
-
- set{
- designTime = value;
- }
- }
-
- IDataParameterCollection IDbCommand.Parameters {
- get {
- return Parameters;
- }
- }
-
- public MySqlParameterCollection Parameters {
- get {
- return parmCollection;
- }
- }
-
- IDbTransaction IDbCommand.Transaction {
- get {
- return Transaction;
- }
-
- set {
- // FIXME: error handling - do not allow
- // setting of transaction if transaction
- // has already begun
- Transaction = (MySqlTransaction) value;
-
- }
- }
-
- public MySqlTransaction Transaction {
- get {
- return trans;
- }
-
- set {
- // FIXME: error handling
- trans = value;
- }
- }
-
- [MonoTODO]
- public UpdateRowSource UpdatedRowSource {
- // FIXME: do this once DbDataAdaptor
- // and DataRow are done
- get {
- throw new NotImplementedException ();
- }
- set {
- throw new NotImplementedException ();
- }
- }
-
- #endregion // Properties
-
- #region Inner Classes
-
- #endregion // Inner Classes
-
- #region Destructors
-
- protected override void Dispose(bool disposing) {
- if(!this.disposed)
- try {
- if(disposing) {
- // release any managed resources
- }
- // release any unmanaged resources
- // close any handles
-
- this.disposed = true;
- }
- finally {
- base.Dispose(disposing);
- }
- }
-
- // aka Finalize()
- ~MySqlCommand () {
- Dispose (false);
- }
-
- #endregion //Destructors
- }
-}
+++ /dev/null
-//
-// Mono.Data.MySql.MyConnection.cs
-//
-// Author:
-// Daniel Morgan (danmorg@sc.rr.com)
-// Tim Coleman (tim@timcoleman.com)
-//
-// (C) Daniel Morgan 2002
-// Copyright (C) Tim Coleman, 2002
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Collections;
-using System.Collections.Specialized;
-using System.ComponentModel;
-using System.Data;
-using System.Data.Common;
-using System.Runtime.InteropServices;
-using System.Text;
-
-namespace Mono.Data.MySql {
-
- public sealed class MySqlConnection : Component, ICloneable, IDbConnection {
-
- #region Fields
-
- private IntPtr mysqlInitStruct = IntPtr.Zero;
- private IntPtr mysqlConn = IntPtr.Zero;
-
- private string connectionString = "";
- private string mysqlConnectionString = "";
-
- private MySqlTransaction trans = null;
- private int connectionTimeout = 15;
- // default for 15 seconds
-
- // MySQL connection string parameters
- string host = "";
- string user = "";
- string passwd = "";
- string dbname = "";
- uint port = MySql.Port;
- string socketName = "";
- uint flags = 0;
-
- // connection state
- private ConnectionState conState = ConnectionState.Closed;
-
- // DataReader state
- //private MySqlDataReader rdr = null;
- private bool dataReaderOpen = false;
- // FIXME: if true, throw an exception if SqlConnection
- // is used for anything other than reading
- // data using SqlDataReader
-
- private string versionString = "Unknown";
- private bool disposed = false;
-
- #endregion // Fields
-
- #region Constructors
-
- // A lot of the defaults were initialized in the Fields
- [MonoTODO]
- public MySqlConnection () {
-
- }
-
- [MonoTODO]
- public MySqlConnection (String connectionString) {
- SetConnectionString (connectionString);
- }
-
- #endregion // Constructors
-
- #region Destructors
-
- protected override void Dispose(bool disposing) {
- if(!this.disposed)
- try {
- if(disposing) {
- // release any managed resources
- trans = null;
- }
- // release any unmanaged resources
- mysqlInitStruct = IntPtr.Zero;
- IntPtr mysqlConn = IntPtr.Zero;
-
- // close any handles
-
- this.disposed = true;
- }
- finally {
- base.Dispose(disposing);
- }
- }
-
- // aka Finalize
- ~MySqlConnection() {
- Dispose (false);
- }
-
- #endregion // Destructors
-
- #region Public Methods
-
- IDbTransaction IDbConnection.BeginTransaction () {
- return BeginTransaction ();
- }
-
- public MySqlTransaction BeginTransaction () {
- return TransactionBegin (); // call private method
- }
-
- IDbTransaction IDbConnection.BeginTransaction (IsolationLevel
- il) {
- return BeginTransaction (il);
- }
-
- public MySqlTransaction BeginTransaction (IsolationLevel il) {
- return TransactionBegin (il); // call private method
- }
-
- [MonoTODO]
- public MySqlTransaction BeginTransaction(string transactionName) {
-
- // FIXME: Can MySQL handle named transactions?
- return TransactionBegin (); // call private method
- }
-
- [MonoTODO]
- public MySqlTransaction BeginTransaction(IsolationLevel iso,\r
- string transactionName) {
-
- // FIXME: Can MySQL handle named transactions?
- return TransactionBegin (iso); // call private method
- }
-
- public void ChangeDatabase (string databaseName) {
- dbname = databaseName;
- int sdb = MySql.SelectDb(mysqlInitStruct, dbname);
- if (sdb != 0) {
- string msg =
- "MySql Error: " +
- "Can not select the " +
- dbname +
- " database because: " +
- MySql.Error(mysqlInitStruct);
- throw new MySqlException (msg);
- }
- }
-
- object ICloneable.Clone() {
- throw new NotImplementedException ();
- }
-
- [MonoTODO]
- public void Close () {
- if(dataReaderOpen == true) {
- // TODO: what do I do if
- // the user Closes the connection
- // without closing the Reader first?
-
- }
- CloseDataSource ();
- }
-
- IDbCommand IDbConnection.CreateCommand () {
- return CreateCommand ();
- }
-
- public MySqlCommand CreateCommand () {
- MySqlCommand sqlcmd = new MySqlCommand ("", this);
-
- return sqlcmd;
- }
-
- [MonoTODO]
- public void Open () {
- if(dbname.Equals(""))
- throw new InvalidOperationException(
- "dbname missing");
- else if(conState == ConnectionState.Open)
- throw new InvalidOperationException(
- "ConnnectionState is already Open");
- else if(connectionString.Equals(String.Empty))
- throw new InvalidOperationException(
- "ConnectionString is not set");
-
- // FIXME: check to make sure we have
- // everything to connect,
- // otherwise, throw an exception
-
- mysqlInitStruct = MySql.Init(IntPtr.Zero);
- if (mysqlInitStruct == IntPtr.Zero) {
- throw new MySqlException("MySQL Init failed.");
- }
-
-
- // *** this is what it should be ***
- //mysqlConn = MySql.Connect(mysqlInitStruct,
- // host.Equals("") ? null : host,
- // user.Equals("") ? null : user,
- // passwd.Equals("") ? null : passwd,
- // dbname.Equals("") ? null : dbname,
- // port,
- // socketName.Equals("") ? null : socketName,
- // flags);
- //
- mysqlConn = MySql.Connect(mysqlInitStruct,
- host,
- user,
- passwd,
- dbname,
- port,
- socketName,
- flags);
- if (mysqlConn == IntPtr.Zero) {
- string msg = "MySQL Connect failed, " +
- MySql.Error(mysqlInitStruct);
- throw new MySqlException(msg);
- }
-
- this.ChangeDatabase (dbname);
-
- // Successfully Connected
- SetupConnection();
- }
-
- #endregion // Public Methods
-
- #region Protected Methods
-
- #endregion
-
- #region Internal Methods
-
- // Used to prevent MySqlConnection
- // from doing anything while
- // MySqlDataReader is open.
- // Open the Reader. (called from MySqlCommand)
- /*
- internal void OpenReader(MySqlDataReader reader) {
- if(dataReaderOpen == true) {
- // TODO: throw exception here?
- // because a reader
- // is already open
- }
- else {
- rdr = reader;
- dataReaderOpen = true;
- }
- }
- */
-
- // Used to prevent MySqlConnection
- // from doing anything while
- // MySqlDataReader is open
- // Close the Reader (called from MySqlCommand)
- // if closeConnection true, Close() the connection
- // this is based on CommandBehavior.CloseConnection
- internal void CloseReader(bool closeConnection) {
- if(closeConnection == true)
- CloseDataSource();
- else
- dataReaderOpen = false;
- }
-
- #endregion // Internal Methods
-
- #region Private Methods
-
- private void SetupConnection() {
- conState = ConnectionState.Open;
-
- versionString = GetDatabaseServerVersion();
- }
-
- private string GetDatabaseServerVersion() {
- MySqlCommand cmd = new MySqlCommand("select version()",this);
- return (string) cmd.ExecuteScalar();
- }
-
- private void CloseDataSource () {
- // FIXME: just a quick hack
- if(conState == ConnectionState.Open) {
- /*
- if(trans != null)
- if(trans.DoingTransaction == true) {
- trans.Rollback();
- // trans.Dispose();
- trans = null;
- }
- */
- conState = ConnectionState.Closed;
- MySql.Close(mysqlInitStruct);
- MySql.ThreadEnd();
- mysqlConn = IntPtr.Zero;
- }
- }
-
- void SetConnectionString (string connectionString) {
- this.connectionString = connectionString;
-
- connectionString += ";";
- NameValueCollection parameters = new NameValueCollection ();
-
- if (connectionString == String.Empty)
- return;
-
- bool inQuote = false;
- bool inDQuote = false;
-
- string name = String.Empty;
- string value = String.Empty;
- StringBuilder sb = new StringBuilder ();
-
- foreach (char c in connectionString) {
- switch (c) {
- case '\'':
- inQuote = !inQuote;
- break;
- case '"' :
- inDQuote = !inDQuote;
- break;
- case ';' :
- if (!inDQuote && !inQuote) {
- if (name != String.Empty && name != null) {
- value = sb.ToString ();
- parameters [name.ToUpper ().Trim ()] = value.Trim ();
- }
- name = String.Empty;
- value = String.Empty;
- sb = new StringBuilder ();
- }
- else
- sb.Append (c);
- break;
- case '=' :
- if (!inDQuote && !inQuote) {
- name = sb.ToString ();
- sb = new StringBuilder ();
- }
- else
- sb.Append (c);
- break;
- default:
- sb.Append (c);
- break;
- }
- }
-
- SetProperties (parameters);
- }
-
- private void SetProperties (NameValueCollection parameters) {
-
- StringBuilder connectionStr = new StringBuilder();
-
- string value;
- foreach (string name in parameters) {
- value = parameters[name];
-
- bool found = true;
- switch (name) {
- case "PORT" :
- port = UInt32.Parse(value);
- break;
- case "DATA SOURCE" :
- case "SERVER" :
- case "HOST" :
- // set DataSource property
- host = value;
- break;
- case "INITIAL CATALOG" :
- case "DATABASE" :
- case "DBNAME" :
- // set Database property
- dbname = value;
- break;
- case "PASSWORD" :
- case "PWD" :
- case "PASSWD" :
- passwd = value;
- break;
- case "USER ID" :
- case "UID" :
- case "USER" :
- user = value;
- break;
- case "SOCKETNAME":
- socketName = value;
- break;
- case "FLAGS" :
- // FIXME: how to get these flags and
- // and pass to MySQL?
- // flags is a bitfield
- flags = UInt32.Parse(value);
- break;
- default:
- found = false;
- // FIXME: throw exception?
- break;
- }
- if (found == true) {
- string valuePair = name + "=" + value;
- connectionStr.Append (valuePair + " ");
- }
- }
- this.mysqlConnectionString = connectionStr.ToString ();
- }
-
- private MySqlTransaction TransactionBegin () {
- // FIXME: need to keep track of
- // transaction in-progress
- trans = new MySqlTransaction ();
- // using internal methods of SqlTransaction
- trans.SetConnection (this);
- trans.Begin();
-
- return trans;
- }
-
- private MySqlTransaction TransactionBegin (IsolationLevel il) {
- // FIXME: need to keep track of
- // transaction in-progress
- trans = new MySqlTransaction ();
- // using internal methods of MySqlTransaction
- trans.SetConnection (this);
- trans.SetIsolationLevel (il);
- trans.Begin();
-
- return trans;
- }
-
- #endregion
-
- #region Public Properties
-
- [MonoTODO]
- public ConnectionState State {
- get {
- return conState;
- }
- }
-
- public string ConnectionString {
- get {
- return connectionString;
- }
- set {
- SetConnectionString (value);
- }
- }
-
- public int ConnectionTimeout {
- get {
- return connectionTimeout;
- }
- }
-
- public string Database {
- get {
- return dbname;
- }
- }
-
- public string DataSource {
- get {
- return host;
- }
- }
-
- public int PacketSize {
- get {
- throw new NotImplementedException ();
- }
- }
-
- public string ServerVersion {
- get {
- return versionString;
- }
- }
-
- #endregion // Public Properties
-
- #region Internal Properties
-
- // For Mono.Data.MySql classes
- // to get the current transaction
- // in progress - if any
- internal MySqlTransaction Transaction {
- get {
- return trans;
- }
- }
-
- // For Mono.Data.MySql classes
- // to get the unmanaged MySql connection
- internal IntPtr NativeMySqlConnection {
- get {
- return mysqlConn;
- }
- }
-
- // For Mono.Data.MySql classes
- // to get the unmanaged MySql connection
- internal IntPtr NativeMySqlInitStruct {
- get {
- return mysqlInitStruct;
- }
- }
-
- // Used to prevent SqlConnection
- // from doing anything while
- // SqlDataReader is open
- internal bool IsReaderOpen {
- get {
- return dataReaderOpen;
- }
- }
-
- #endregion // Internal Properties
-
- #region Events
-/*
- public event
- MyInfoMessageEventHandler InfoMessage;
-
- public event
- StateChangeEventHandler StateChange;
-*/
- #endregion
-
- }
-}
+++ /dev/null
-//
-// Mono.Data.MySql.MySqlDataAdapter.cs
-//
-// Author:
-// Tim Coleman (tim@timcoleman.com)
-// Daniel Morgan <danmorg@sc.rr.com>
-//
-// Copyright (C) Tim Coleman, 2002
-// Copyright (C) Daniel Morgan, 2002
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.ComponentModel;
-using System.Data;
-using System.Data.Common;
-
-namespace Mono.Data.MySql
-{
- /// <summary>
- /// Represents a set of command-related properties that are used
- /// to fill the DataSet and update a data source, all this
- /// from a SQL database.
- /// </summary>
- public sealed class MySqlDataAdapter : DbDataAdapter, IDbDataAdapter
- {
- #region Fields
-
- MySqlCommand deleteCommand;
- MySqlCommand insertCommand;
- MySqlCommand selectCommand;
- MySqlCommand updateCommand;
-
- static readonly object EventRowUpdated = new object();
- static readonly object EventRowUpdating = new object();
-
- #endregion
-
- #region Constructors
-
- public MySqlDataAdapter ()
- : this (new MySqlCommand ())
- {
- }
-
- public MySqlDataAdapter (MySqlCommand selectCommand)
- {
- DeleteCommand = new MySqlCommand ();
- InsertCommand = new MySqlCommand ();
- SelectCommand = selectCommand;
- UpdateCommand = new MySqlCommand ();
- }
-
- public MySqlDataAdapter (string selectCommandText, MySqlConnection selectConnection)
- : this (new MySqlCommand (selectCommandText, selectConnection))
- {
- }
-
- public MySqlDataAdapter (string selectCommandText, string selectConnectionString)
- : this (selectCommandText, new MySqlConnection (selectConnectionString))
- {
- }
-
- #endregion
-
- #region Properties
-
- public MySqlCommand DeleteCommand {
- get { return deleteCommand; }
- set { deleteCommand = value; }
- }
-
- public MySqlCommand InsertCommand {
- get { return insertCommand; }
- set { insertCommand = value; }
- }
-
- public MySqlCommand SelectCommand {
- get { return selectCommand; }
- set { selectCommand = value; }
- }
-
- public MySqlCommand UpdateCommand {
- get { return updateCommand; }
- set { updateCommand = value; }
- }
-
- IDbCommand IDbDataAdapter.DeleteCommand {
- get { return DeleteCommand; }
- set {
- if (!(value is MySqlCommand))
- throw new ArgumentException ();
- DeleteCommand = (MySqlCommand)value;
- }
- }
-
- IDbCommand IDbDataAdapter.InsertCommand {
- get { return InsertCommand; }
- set {
- if (!(value is MySqlCommand))
- throw new ArgumentException ();
- InsertCommand = (MySqlCommand)value;
- }
- }
-
- IDbCommand IDbDataAdapter.SelectCommand {
- get { return SelectCommand; }
- set {
- if (!(value is MySqlCommand))
- throw new ArgumentException ();
- SelectCommand = (MySqlCommand)value;
- }
- }
-
- IDbCommand IDbDataAdapter.UpdateCommand {
- get { return UpdateCommand; }
- set {
- if (!(value is MySqlCommand))
- throw new ArgumentException ();
- UpdateCommand = (MySqlCommand)value;
- }
- }
-
-
- ITableMappingCollection IDataAdapter.TableMappings {
- get { return TableMappings; }
- }
-
- #endregion // Properties
-
- #region Methods
-
- protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
- {
- return new MySqlRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
- }
-
-
- protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
- {
- return new MySqlRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
- }
-
- protected override void OnRowUpdated (RowUpdatedEventArgs value)
- {
- MySqlRowUpdatedEventHandler handler = (MySqlRowUpdatedEventHandler) Events[EventRowUpdated];
- if ((handler != null) && (value is MySqlRowUpdatedEventArgs))
- handler (this, (MySqlRowUpdatedEventArgs) value);
- }
-
- protected override void OnRowUpdating (RowUpdatingEventArgs value)
- {
- MySqlRowUpdatingEventHandler handler = (MySqlRowUpdatingEventHandler) Events[EventRowUpdating];
- if ((handler != null) && (value is MySqlRowUpdatingEventArgs))
- handler (this, (MySqlRowUpdatingEventArgs) value);
- }
-
- #endregion // Methods
-
- #region Events and Delegates
-
- public event MySqlRowUpdatedEventHandler RowUpdated {
- add { Events.AddHandler (EventRowUpdated, value); }
- remove { Events.RemoveHandler (EventRowUpdated, value); }
- }
-
- public event MySqlRowUpdatingEventHandler RowUpdating {
- add { Events.AddHandler (EventRowUpdating, value); }
- remove { Events.RemoveHandler (EventRowUpdating, value); }
- }
-
- #endregion // Events and Delegates
-
- }
-}
+++ /dev/null
-//
-// Mono.Data.MySql.MySqlDataReader.cs
-//
-// Author:
-// Rodrigo Moya (rodrigo@ximian.com)
-// Daniel Morgan (danmorg@sc.rr.com)
-//
-// (C) Ximian, Inc 2002
-// (C) Daniel Morgan 2002
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Collections;
-using System.ComponentModel;
-using System.Data;
-using System.Data.Common;
-using System.Runtime.InteropServices;
-
-namespace Mono.Data.MySql {
- /// <summary>
- /// Provides a means of reading one or more forward-only streams
- /// of result sets obtained by executing a command
- /// at a SQL database.
- /// </summary>
- public sealed class MySqlDataReader : MarshalByRefObject,
- IEnumerable, IDataReader, IDisposable, IDataRecord
- {
-
- #region Fields
-
- private MySqlCommand cmd;
-
- // field meta data
- private string[] fieldName;
- private MySqlEnumFieldTypes[] fieldType; // MySQL data type
- private DbType[] fieldDbType; // DbType translated from MySQL type
- private uint[] fieldLength;
- private uint[] fieldMaxLength;
- private uint[] fieldFlags;
- // field data value
- private object[] dataValue;
-
- private bool open = false;
-
- private int recordsAffected = -1;
- private int currentQuery = 0;
-
- private int currentRow = -1;
- private IntPtr res = IntPtr.Zero;
- private IntPtr row = IntPtr.Zero;
-
- private int numFields;
- private int numRows;
-
- private CommandBehavior cmdBehavior;
-
- private bool disposed = false;
-
- #endregion // Fields
-
- #region Constructors
-
- internal MySqlDataReader (MySqlCommand sqlCmd, CommandBehavior behavior) {
-
- cmd = sqlCmd;
- open = true;
- // cmd.OpenReader(this);
- cmdBehavior = behavior;
- }
-
- #endregion // Fields
-
- #region Public Methods
-
- [MonoTODO]
- public void Close() {
- open = false;
-
- // free MySqlDataReader resources in SqlCommand
- // and allow SqlConnection to be used again
- //cmd.CloseReader();
-
- // TODO: get parameters from result
-
- Dispose(true);
- }
-
- public DataTable GetSchemaTable() {
-
- DataTable dataTableSchema = null;
- // Only Results from SQL SELECT Queries
- // get a DataTable for schema of the result
- // otherwise, DataTable is null reference
- if(numFields > 0) {
-
- dataTableSchema = new DataTable ("SchemaTable");
-
- dataTableSchema.Columns.Add ("ColumnName", typeof (string));
- dataTableSchema.Columns.Add ("ColumnOrdinal", typeof (int));
- dataTableSchema.Columns.Add ("ColumnSize", typeof (int));
- dataTableSchema.Columns.Add ("NumericPrecision", typeof (int));
- dataTableSchema.Columns.Add ("NumericScale", typeof (int));
- dataTableSchema.Columns.Add ("IsUnique", typeof (bool));
- dataTableSchema.Columns.Add ("IsKey", typeof (bool));
- DataColumn dc = dataTableSchema.Columns["IsKey"];
- dc.AllowDBNull = true; // IsKey can have a DBNull
- dataTableSchema.Columns.Add ("BaseCatalogName", typeof (string));
- dataTableSchema.Columns.Add ("BaseColumnName", typeof (string));
- dataTableSchema.Columns.Add ("BaseSchemaName", typeof (string));
- dataTableSchema.Columns.Add ("BaseTableName", typeof (string));
- dataTableSchema.Columns.Add ("DataType", typeof(Type));
- dataTableSchema.Columns.Add ("AllowDBNull", typeof (bool));
- dataTableSchema.Columns.Add ("ProviderType", typeof (int));
- dataTableSchema.Columns.Add ("IsAliased", typeof (bool));
- dataTableSchema.Columns.Add ("IsExpression", typeof (bool));
- dataTableSchema.Columns.Add ("IsIdentity", typeof (bool));
- dataTableSchema.Columns.Add ("IsAutoIncrement", typeof (bool));
- dataTableSchema.Columns.Add ("IsRowVersion", typeof (bool));
- dataTableSchema.Columns.Add ("IsHidden", typeof (bool));
- dataTableSchema.Columns.Add ("IsLong", typeof (bool));
- dataTableSchema.Columns.Add ("IsReadOnly", typeof (bool));
-\r
- DataRow schemaRow;
-
- Type typ;
-
- for (int i = 0; i < numFields; i += 1 ) {
-
- schemaRow = dataTableSchema.NewRow ();
-
- schemaRow["ColumnName"] = fieldName[i];
- schemaRow["ColumnOrdinal"] = i + 1;
-
- schemaRow["ColumnSize"] = (int) fieldMaxLength[i];
- schemaRow["NumericPrecision"] = 0;
- schemaRow["NumericScale"] = 0;
-
- if((cmdBehavior & CommandBehavior.KeyInfo) == CommandBehavior.KeyInfo) {
- // TODO: need to get KeyInfo
- schemaRow["IsUnique"] = false;
- schemaRow["IsKey"] = false;
- }
- else {
- schemaRow["IsUnique"] = false;
- schemaRow["IsKey"] = DBNull.Value;
- }
- schemaRow["BaseCatalogName"] = "";
-
- schemaRow["BaseColumnName"] = fieldName[i];
- schemaRow["BaseSchemaName"] = "";
- schemaRow["BaseTableName"] = "";
-
- typ = MySqlHelper.DbTypeToSystemType (fieldDbType[i]);\r
- schemaRow["DataType"] = typ;\r
-
- schemaRow["AllowDBNull"] = false;
-
- schemaRow["ProviderType"] = (int) fieldType[i];
- schemaRow["IsAliased"] = false;
- schemaRow["IsExpression"] = false;
- schemaRow["IsIdentity"] = false;
- schemaRow["IsAutoIncrement"] = false;
- schemaRow["IsRowVersion"] = false;
- schemaRow["IsHidden"] = false;
- schemaRow["IsLong"] = false;
- schemaRow["IsReadOnly"] = false;
-
- dataTableSchema.Rows.Add (schemaRow);
- }
- }
-
- return dataTableSchema;
- }
-
- private void ClearFields () {
- numRows = 0;
- numFields = 0;
- fieldName = null;
- fieldType = null;
- fieldLength = null;
- fieldMaxLength = null;
- fieldFlags = null;
- dataValue = null;
- }
-
- public bool NextResult () {
-
- // reset
- recordsAffected = -1;
- currentRow = -1;
-
- bool resultReturned;
- res = cmd.NextResult (out resultReturned);
- if (resultReturned == false)
- return false; // no result returned
-
- if ((cmdBehavior & CommandBehavior.SingleResult) == CommandBehavior.SingleResult)
- if (currentQuery > 0) {
- if(res == IntPtr.Zero)
- recordsAffected = (int) MySql.AffectedRows(cmd.Connection.NativeMySqlInitStruct);
- ClearFields();
- return true; // result returned
- }
-
- if((cmdBehavior & CommandBehavior.SchemaOnly) == CommandBehavior.SchemaOnly) {
- ClearFields ();
- return false; // no result returned
- }
-
- if(res == IntPtr.Zero) {
- // no result set returned
- recordsAffected = (int) MySql.AffectedRows (cmd.Connection.NativeMySqlInitStruct);
- ClearFields();
- }
- else {
- dataValue = null;
-
- // get meta data about result set
- numRows = MySql.NumRows(res);
- numFields = MySql.NumFields(res);
- // get meta data about each field
- fieldName = new string[numFields];
- fieldType = new MySqlEnumFieldTypes[numFields];
- fieldLength = new uint[numFields];
- fieldMaxLength = new uint[numFields];
- fieldFlags = new uint[numFields];
-
- fieldDbType = new DbType[numFields];
-
- // marshal each meta data field
- // into field* arrays
- MySqlMarshalledField marshField = null;
- for (int i = 0; i < numFields; i++) {
- // marshal field
- marshField = (MySqlMarshalledField) Marshal.PtrToStructure(MySql.FetchField(res),
- typeof(MySqlMarshalledField));
-
- // copy memebers in marshalField to fields[i]
- fieldName[i] = marshField.Name;
- int myType = marshField.FieldType;
- fieldType[i] = (MySqlEnumFieldTypes) myType;
- fieldLength[i] = marshField.Length;
- fieldMaxLength[i] = marshField.MaxLength;
- fieldFlags[i] = marshField.Flags;
-
- fieldDbType[i] = MySqlHelper.MySqlTypeToDbType((MySqlEnumFieldTypes)fieldType[i]);
- marshField = null;
- }
- }
- return true; // result returned
- }
-
- public bool Read() {
-
- dataValue = null;
-
- if(currentRow < numRows - 1) {
-
- currentRow++;
-
- if(numFields > 0 && currentRow > 0)\r
- if((cmdBehavior & CommandBehavior.SingleRow) == \r
- CommandBehavior.SingleRow) {\r
-\r
- currentRow = numRows - 1;\r
- return false; // EOF\r
- }\r
-
- row = MySql.FetchRow (res);
- if (row == IntPtr.Zero) {
- MySql.FreeResult (res);
- res = IntPtr.Zero;
- return false; // EOF
- }
- else {
- dataValue = new object[numFields];
- for (int col = 0; col < numFields; col++) {
- GetDataValue (row, col);
- }
- }
- return true; // not EOF
- }
- return false; // EOF
- }
-
- void GetDataValue (IntPtr row, int col) {
- // marshal column data value
- string objValue = cmd.GetColumnData(row, col);
-
- // tranlate from native MySql c type
- // to a .NET type here
- dataValue[col] = MySqlHelper.ConvertDbTypeToSystem (fieldType[col],
- fieldDbType[col], objValue);
-
- // TODO: for CommandBehavior.SequentialAccess -
- // used for reading Large OBjects
- //if((cmdBehavior & CommandBehavior.SequentialAccess) ==
- // CommandBehavior.SequentialAccess) {
- //}
- }
-
- [MonoTODO]
- public byte GetByte (int i) {
- throw new NotImplementedException ();
- }
-
- // TODO: CommandBehavior.SequentialAccess
- // and handling LOBs
- [MonoTODO]
- public long GetBytes (int i, long fieldOffset,
- byte[] buffer, int bufferOffset,
- int length) {
-
- throw new NotImplementedException ();
- }
-
- [MonoTODO]
- public char GetChar (int i) {
- throw new NotImplementedException ();
- }
-
- // TODO: CommandBehavior.SequentialAccess
- // and handling LOBs
- [MonoTODO]
- public long GetChars (int i, long fieldOffset,
- char[] buffer, int bufferOffset,
- int length) {
-
- throw new NotImplementedException ();
- }
-
- [MonoTODO]
- public IDataReader GetData (int i) {
- throw new NotImplementedException ();
- }
-
- public string GetDataTypeName (int i) {
- return MySqlHelper.GetMySqlTypeName (fieldType[i]);
- }
-
- public DateTime GetDateTime(int i) {
- return (DateTime) dataValue[i];
- }
-
- public decimal GetDecimal(int i) {
- return (decimal) dataValue[i];
- }
-
- public double GetDouble(int i) {
- return (double) dataValue[i];
- }
-
- public Type GetFieldType(int i) {
- return MySqlHelper.DbTypeToSystemType (fieldDbType[i]);
- }
-
- public float GetFloat(int i) {
- return (float) dataValue[i];
- }
-
- public Guid GetGuid(int i) {
- throw new NotImplementedException ();
- }
-
- public short GetInt16(int i) {
- return (short) dataValue[i];
- }
-
- public int GetInt32(int i) {
- return (int) dataValue[i];
- }
-
- public long GetInt64(int i) {
- return (long) dataValue[i];
- }
-
- public string GetName(int i) {
- return fieldName[i];
- }
-
- public int GetOrdinal (string name) {
-
- int i;
-
- for(i = 0; i < numFields; i++) {
- if(fieldName[i].Equals (name))
- return i;
- }
-
- for(i = 0; i < numFields; i++) {
- string ta;
- string n;
-
- ta = fieldName[i].ToUpper ();
- n = name.ToUpper ();
-
- if(ta.Equals (n)) {
- return i;
- }
- }
-
- throw new MissingFieldException ("Missing field: " + name);
- }
-
- public string GetString (int i) {
- return (string) dataValue[i];
- }
-
- public object GetValue (int i) {
- return dataValue[i];
- }
-
- public int GetValues(object[] values)
- {
- Array.Copy (dataValue, values, dataValue.Length);
- return dataValue.Length;
- }
-
- public bool IsDBNull(int i) {
- if(dataValue[i] == DBNull.Value)
- return true;
- return false;
- }
-
- public bool GetBoolean(int i) {
- return (bool) dataValue[i];
- }
-
- IEnumerator IEnumerable.GetEnumerator () {
- return new DbEnumerator (this);
- }
-
- #endregion // Public Methods
-
- #region Destructors
-
- private void Dispose(bool disposing) {
- if(!this.disposed) {
- if(disposing) {
- // release any managed resources
- cmd = null;
- fieldName = null;
- fieldType = null;
- fieldDbType = null;
- fieldLength = null;
- fieldMaxLength = null;
- fieldFlags = null;
- dataValue = null;
- }
- // release any unmanaged resources
-
- // clear unmanaged MySQL result set
- row = IntPtr.Zero;
- if(res != IntPtr.Zero) {
- MySql.FreeResult(res);
- res = IntPtr.Zero;
- }
-
- // close any handles
- this.disposed = true;
- }
- }
-
- void IDisposable.Dispose() {
- Dispose(true);
- }
-
- // aka Finalize
- ~MySqlDataReader() {
- Dispose (false);
- }
-
- #endregion // Destructors
-
- #region Properties
-
- public int Depth {
- get {
- return 0; // always return zero, unless
- // this provider will allow
- // nesting of a row
- }
- }
-
- public bool IsClosed {
- get {
- if(open == false)
- return true;
- else
- return false;
- }
- }
-
- public int RecordsAffected {
- get {
- return recordsAffected;
- }
- }
-
- public int FieldCount {
- get {
- return numFields;
- }
- }
-
- public object this[string name] {
- get {
- int i;
-
- for(i = 0; i < numFields; i++) {
- if(fieldName[i].Equals(name))
- return dataValue[i];
- }
-
- for(i = 0; i < numFields; i++) {
- string ta;
- string n;
-
- ta = fieldName[i].ToUpper();
- n = name.ToUpper();
-
- if(ta.Equals(n)) {
- return dataValue[i];
- }
- }
-
- throw new MissingFieldException("Missing field: " + name);
- }
- }
-
- public object this[int i] {
- get {
- return dataValue[i];
- }
- }
-
- #endregion // Properties
- }
-}
+++ /dev/null
-//
-// Mono.Data.MySql.MySqlError
-//
-// Author:
-// Daniel Morgan <danmorg@sc.rr.com>
-//
-// (c)copyright 2002 Daniel Morgan
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Collections;
-using System.ComponentModel;
-using System.Data;
-using System.Data.Common;
-
-namespace Mono.Data.MySql\r
-{\r
- public class MySqlError\r
- {\r
- private string message;\r
- private string source;\r
- private string sqlstate;\r
- private int nativeerror;\r
-\r
- #region Constructors
-\r
- internal MySqlError(string Source)\r
- {\r
- nativeerror = 1;\r
- source = Source;\r
- message = "Error in " + source;\r
- sqlstate = "";\r
- }\r
-\r
- #endregion // Constructors
-
- #region Properties
-\r
- public string Message\r
- {\r
- get\r
- {\r
- return message;\r
- }\r
- }\r
-\r
- public int NativeError\r
- {\r
- get\r
- {\r
- return nativeerror;\r
- }\r
- }\r
-\r
- public string Source\r
- {\r
- get\r
- {\r
- return source;\r
- }\r
- }\r
-\r
- public string SQLState\r
- {\r
- get\r
- {\r
- return sqlstate;\r
- }\r
- }\r
-
- #endregion // Properties
-\r
- }\r
-}
\ No newline at end of file
+++ /dev/null
-//
-// Mono.Data.MySql.MySqlErrorCollection
-//
-// Author:
-// Daniel Morgan <danmorg@sc.rr.com>
-//
-// (c)Copyright 2002 Daniel Morgan
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Collections;
-using System.ComponentModel;
-using System.Data;
-using System.Data.Common;
-
-namespace Mono.Data.MySql\r
-{\r
- public sealed class MySqlErrorCollection : ICollection, IEnumerable
- {
- #region Fields
-
- ArrayList list = new ArrayList ();
-
- #endregion // Fields
-
- #region Properties
-
- public int Count \r
- {
- get \r
- {
- return list.Count;
- }
- }
-
- public MySqlError this[int index] \r
- {
- get \r
- {
- return (MySqlError) list[index];
- }
- }
-
- object ICollection.SyncRoot \r
- {
- get \r
- {
- return list.SyncRoot;
- }
- }
-
- bool ICollection.IsSynchronized \r
- {
- get \r
- {
- return list.IsSynchronized;
- }
- }
-
- #endregion // Properties
-
- #region Methods
-
- public void Add (MySqlError error)
- {
- list.Add ((object) error);
- }
-
- [MonoTODO]
- public void CopyTo (Array array, int index)
- {
- ((MySqlError[])(list.ToArray ())).CopyTo (array, index);
- }
-
- public IEnumerator GetEnumerator ()
- {
- return list.GetEnumerator ();
- }
-
- IEnumerator IEnumerable.GetEnumerator ()
- {
- return GetEnumerator ();
- }
-
- #endregion // Methods
- }
-}
+++ /dev/null
-//
-// Mono.Data.MySql.Exception
-//
-// Author:
-// Daniel Morgan <danmorg@sc.rr.com>
-//
-// (c)Copyright 2002 Daniel Morgan
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Collections;
-using System.ComponentModel;
-using System.Data;
-using System.Data.Common;
-using System.Runtime.InteropServices;
-using System.Runtime.Serialization;
-
-namespace Mono.Data.MySql {\r
- public class MySqlException : SystemException {\r
- MySqlErrorCollection errors;\r
-\r
- internal MySqlException (MySqlError error) : base (error.Message) {\r
- errors = new MySqlErrorCollection ();\r
- errors.Add (error);\r
- }\r
-\r
- internal MySqlException (string message) : base (message) {\r
- MySqlError error = new MySqlError (message);\r
- errors = new MySqlErrorCollection ();\r
- errors.Add (error);\r
- }\r
-\r
- #region Properties\r
-\r
- public int ErrorCode {
- get {
- return errors[0].NativeError;
- }
- }
-
- public MySqlErrorCollection Errors {
- get {
- return errors;
- }
- }
-
- public override string Source {
- get {
- return errors[0].Source;
- }
- }
-\r
- #endregion // Properties\r
-\r
- #region Methods
-
- [MonoTODO]
- public override void GetObjectData (SerializationInfo si, StreamingContext context) {
- throw new NotImplementedException ();
- }
-
- #endregion // Methods\r
- }\r
-}\r
+++ /dev/null
-//
-// Mono.Data.MySql.MySqlParameter.cs
-//
-// Author:
-// Rodrigo Moya (rodrigo@ximian.com)
-// Daniel Morgan (danmorg@sc.rr.com)
-//
-// (C) Ximian, Inc. 2002
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-using System.ComponentModel;
-using System.Data;
-using System.Data.Common;
-using System.Runtime.InteropServices;
-
-namespace Mono.Data.MySql
-{
- /// <summary>
- /// Represents a parameter to a Command object, and optionally,
- /// its mapping to DataSet columns; and is implemented by .NET
- /// data providers that access data sources.
- /// </summary>
- //public sealed class MySqlParameter : MarshalByRefObject,
- // IDbDataParameter, IDataParameter, ICloneable
- public sealed class MySqlParameter : IDbDataParameter, IDataParameter
- {
- private string parmName;
- private DbType dbtype;
- private object objValue;
- private int size;
- private string sourceColumn;
- private ParameterDirection direction;
- private bool isNullable;
- private byte precision;
- private byte scale;
- private DataRowVersion sourceVersion;
- private int offset;
-
- [MonoTODO]
- public MySqlParameter () {
-
- }
-
- [MonoTODO]
- public MySqlParameter (string parameterName, object value) {
- this.parmName = parameterName;
- this.objValue = value;
- }
-
- [MonoTODO]
- public MySqlParameter(string parameterName, DbType dbType) {
- this.parmName = parameterName;
- this.dbtype = dbType;
- }
-
- [MonoTODO]
- public MySqlParameter(string parameterName, DbType dbType,
- int size) {
-
- this.parmName = parameterName;
- this.dbtype = dbType;
- this.size = size;
- }
-
- [MonoTODO]
- public MySqlParameter(string parameterName, DbType dbType,
- int size, string sourceColumn) {
-
- this.parmName = parameterName;
- this.dbtype = dbType;
- this.size = size;
- this.sourceColumn = sourceColumn;
- }
-
- [MonoTODO]
- public MySqlParameter(string parameterName, DbType dbType,
- int size, ParameterDirection direction,
- bool isNullable, byte precision,
- byte scale, string sourceColumn,
- DataRowVersion sourceVersion, object value) {
-
- this.parmName = parameterName;
- this.dbtype = dbType;
- this.size = size;
- this.sourceColumn = sourceColumn;
- this.direction = direction;
- this.isNullable = isNullable;
- this.precision = precision;
- this.scale = scale;
- this.sourceVersion = sourceVersion;
- this.objValue = value;
- }
-
- [MonoTODO]
- public DbType DbType {
- get {
- return dbtype;
- }
- set {
- dbtype = value;
- }
- }
-
- [MonoTODO]
- public ParameterDirection Direction {
- get {
- return direction;
- }
- set {
- direction = value;
- }
- }
-
- [MonoTODO]
- public bool IsNullable {
- get {
- return isNullable;
- }
- }
-
- [MonoTODO]
- public int Offset {
- get {
- return offset;
- }
-
- set {
- offset = value;
- }
- }
-
-
- string IDataParameter.ParameterName {
- get {
- return parmName;
- }
-
- set {
- parmName = value;
- }
- }
-
- public string ParameterName {
- get {
- return parmName;
- }
-
- set {
- parmName = value;
- }
- }
-
- [MonoTODO]
- public string SourceColumn {
- get {
- return sourceColumn;
- }
-
- set {
- sourceColumn = value;
- }
- }
-
- [MonoTODO]
- public DataRowVersion SourceVersion {
- get {
- return sourceVersion;
- }
-
- set {
- sourceVersion = value;
- }
- }
-
- [MonoTODO]
- public object Value {
- get {
- return objValue;
- }
-
- set {
- objValue = value;
- }
- }
-
- [MonoTODO]
- public byte Precision {
- get {
- return precision;
- }
-
- set {
- precision = value;
- }
- }
-
- [MonoTODO]
- public byte Scale {
- get {
- return scale;
- }
-
- set {
- scale = value;
- }
- }
-
- [MonoTODO]
- public int Size
- {
- get {
- return size;
- }
-
- set {
- size = value;
- }
- }
-
- [MonoTODO]
- public override string ToString() {
- return parmName;
- }
- }
-}
+++ /dev/null
-//
-// Mono.Data.MySql.MySqlParameterCollection.cs
-//
-// Author:
-// Rodrigo Moya (rodrigo@ximian.com)
-// Daniel Morgan (danmorg@sc.rr.com)
-//
-// (C) Ximian, Inc 2002
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.ComponentModel;
-using System.Data;
-using System.Data.Common;
-using System.Collections;
-
-namespace Mono.Data.MySql
-{
- /// <summary>
- /// Collects all parameters relevant to a Command object
- /// and their mappings to DataSet columns.
- /// </summary>
- public sealed class MySqlParameterCollection : MarshalByRefObject,
- IDataParameterCollection, IList, ICollection, IEnumerable
- {
- private ArrayList parameterList = new ArrayList();
-
- [MonoTODO]
- public IEnumerator GetEnumerator()
- {
- return new MySqlParameterEnumerator (parameterList);
- }
-
- public int Add( object value)
- {
- // Call the add version that receives a SqlParameter
-
- // Check if value is a MySqlParameter.
- CheckType(value);
- Add((MySqlParameter) value);
-
- return IndexOf (value);
- }
-
-
- public MySqlParameter Add(MySqlParameter value)
- {
- parameterList.Add(value);
- return value;
- }
-
-
- public MySqlParameter Add(string parameterName, object value)
- {
- MySqlParameter sqlparam = new MySqlParameter();
- sqlparam.Value = value;
- // TODO: Get the DbType from system type of value.
-
- return Add(sqlparam);
- }
-
-
- public MySqlParameter Add(string parameterName, DbType dbType)
- {
- MySqlParameter sqlparam = new MySqlParameter();
- sqlparam.ParameterName = parameterName;
- sqlparam.DbType = dbType;
- return Add(sqlparam);
- }
-
-
- public MySqlParameter Add(string parameterName,
- DbType dbType, int size)
- {
- MySqlParameter sqlparam = new MySqlParameter();
- sqlparam.ParameterName = parameterName;
- sqlparam.DbType = dbType;
- sqlparam.Size = size;
- return Add(sqlparam);
- }
-
-
- public MySqlParameter Add(string parameterName,
- DbType dbType, int size, string sourceColumn)
- {
- MySqlParameter sqlparam = new MySqlParameter();
- sqlparam.ParameterName = parameterName;
- sqlparam.DbType = dbType;
- sqlparam.Size = size;
- sqlparam.SourceColumn = sourceColumn;
- return Add(sqlparam);
- }
-
- [MonoTODO]
- public void Clear()
- {
- throw new NotImplementedException ();
- }
-
-
- public bool Contains(object value)
- {
- // Check if value is a SqlParameter
- CheckType(value);
- return Contains(((MySqlParameter)value).ParameterName);
- }
-
-
- [MonoTODO]
- public bool Contains(string value)
- {
- for(int p = 0; p < parameterList.Count; p++) {
- if(((MySqlParameter)parameterList[p]).ParameterName.Equals(value))
- return true;
- }
- return false;
- }
-
- [MonoTODO]
- public void CopyTo(Array array, int index)
- {
- throw new NotImplementedException ();
- }
-
-
- public int IndexOf(object value)
- {
- // Check if value is a SqlParameter
- CheckType(value);
- return IndexOf(((MySqlParameter)value).ParameterName);
- }
-
-
- public int IndexOf(string parameterName)
- {
- int p = -1;
-
- for(p = 0; p < parameterList.Count; p++) {
- if(((MySqlParameter)parameterList[p]).ParameterName.Equals(parameterName))
- return p;
- }
- return p;
- }
-
- [MonoTODO]
- public void Insert(int index, object value)
- {
- throw new NotImplementedException ();
- }
-
- [MonoTODO]
- public void Remove(object value)
- {
- throw new NotImplementedException ();
- }
-
- [MonoTODO]
- public void RemoveAt(int index)
- {
- throw new NotImplementedException ();
- }
-
- [MonoTODO]
- public void RemoveAt(string parameterName)
- {
- throw new NotImplementedException ();
- }
-
- [MonoTODO]
- public int Count {
- get {
- return parameterList.Count;
- }
- }
-
- object IList.this[int index] {
- [MonoTODO]
- get {
- return (MySqlParameter) this[index];
- }
-
- [MonoTODO]
- set {
- this[index] = (MySqlParameter) value;
- }
- }
-
- public MySqlParameter this[int index] {
- get {
- return (MySqlParameter) parameterList[index];
- }
-
- set {
- parameterList[index] = (MySqlParameter) value;
- }
- }
-
- object IDataParameterCollection.this[string parameterName] {
- [MonoTODO]
- get {
- return this[parameterName];
- }
-
- [MonoTODO]
- set {
- CheckType(value);
- this[parameterName] = (MySqlParameter) value;
- }
- }
-
- public MySqlParameter this[string parameterName] {
- get {
- for(int p = 0; p < parameterList.Count; p++) {
- if(parameterName.Equals(((MySqlParameter)parameterList[p]).ParameterName))
- return (MySqlParameter) parameterList[p];
- }
- throw new IndexOutOfRangeException("The specified name does not exist: " + parameterName);
- }
-
- set {
- for(int p = 0; p < parameterList.Count; p++) {
- if(parameterName.Equals(((MySqlParameter)parameterList[p]).ParameterName))
- parameterList[p] = value;
- }
- throw new IndexOutOfRangeException("The specified name does not exist: " + parameterName);
- }
- }
-
- bool IList.IsFixedSize {
- get {
- throw new NotImplementedException ();
- }
- }
-
- bool IList.IsReadOnly {
- get {
- throw new NotImplementedException ();
- }
- }
-
- bool ICollection.IsSynchronized {
- get {
- throw new NotImplementedException ();
- }
- }
-
- object ICollection.SyncRoot {
- get {
- throw new NotImplementedException ();
- }
- }
-
- /// <summary>
- /// This method checks if the parameter value is of
- /// MySqlParameter type. If it doesn't, throws an InvalidCastException.
- /// </summary>
- private void CheckType(object value)
- {
- if(!(value is MySqlParameter))
- throw new InvalidCastException("Only MySqlParameter objects can be used.");
- }
-
- private class MySqlParameterEnumerator : IEnumerator {\r
- public MySqlParameterEnumerator (IList list) {\r
- this.list = list;\r
- Reset ();\r
- }\r
-\r
- public object Current {\r
- get {\r
- if (ptr >= list.Count)\r
- throw new InvalidOperationException ();\r
-\r
- return list[ptr];\r
- }\r
- }\r
-\r
- public bool MoveNext () {\r
- if (ptr > list.Count)\r
- throw new InvalidOperationException ();\r
- \r
- return ++ ptr < list.Count;\r
- }\r
-\r
- public void Reset () {\r
- ptr = -1;\r
- }\r
-\r
- private IList list;\r
- private int ptr;\r
- }
- }
-}
+++ /dev/null
-//
-// Mono.Data.MySql.MySqlRowUpdatedEventArgs.cs
-//
-// Author:
-// Tim Coleman (tim@timcoleman.com)
-// Daniel Morgan <danmorg@sc.rr.com>
-//
-// Copyright (C) Tim Coleman, 2002
-// Copyright (C) Daniel Morgan, 2002
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Data;
-using System.Data.Common;
-
-namespace Mono.Data.MySql {
- public sealed class MySqlRowUpdatedEventArgs : RowUpdatedEventArgs
- {
- [MonoTODO]
- public MySqlRowUpdatedEventArgs (DataRow row, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
- : base (row, command, statementType, tableMapping)
- {
- throw new NotImplementedException ();
- }
-
- [MonoTODO]
- public new MySqlCommand Command {
- get { throw new NotImplementedException (); }
- }
-
- [MonoTODO]
- ~MySqlRowUpdatedEventArgs ()
- {
- throw new NotImplementedException ();
- }
-
- }
-}
+++ /dev/null
-//
-// Mono.Data.MySql.MySqlRowUpdatedEventHandler.cs
-//
-// Author:
-// Tim Coleman (tim@timcoleman.com)
-//
-// Copyright (C) Tim Coleman, 2002
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-namespace Mono.Data.MySql {
- public delegate void MySqlRowUpdatedEventHandler(object sender, MySqlRowUpdatedEventArgs e);
-}
+++ /dev/null
-//
-// Mono.Data.MySql.MySqlRowUpdatingEventArgs.cs
-//
-// Author:
-// Tim Coleman (tim@timcoleman.com)
-//
-// Copyright (C) Tim Coleman, 2002
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Data;
-using System.Data.Common;
-
-namespace Mono.Data.MySql
-{
- public sealed class MySqlRowUpdatingEventArgs : RowUpdatingEventArgs
- {
- [MonoTODO]
- public MySqlRowUpdatingEventArgs (DataRow row, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
- : base (row, command, statementType, tableMapping)
- {
- throw new NotImplementedException ();
- }
-
- [MonoTODO]
- public new MySqlCommand Command {
- get { throw new NotImplementedException (); }
- set { throw new NotImplementedException (); }
- }
-
- [MonoTODO]
- ~MySqlRowUpdatingEventArgs() {
- throw new NotImplementedException ();
- }
- }
-}
+++ /dev/null
-//
-// Mono.Data.MySql.MySqlRowUpdatingEventHandler.cs
-//
-// Author:
-// Tim Coleman (tim@timcoleman.com)
-//
-// Copyright (C) Tim Coleman, 2002
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Data;
-
-namespace Mono.Data.MySql {
- public delegate void MySqlRowUpdatingEventHandler(object sender, MySqlRowUpdatingEventArgs e);
-}
+++ /dev/null
-//
-// Mono.Data.MySql.MySqlTransaction.cs
-//
-// Author:
-// Rodrigo Moya (rodrigo@ximian.com)
-// Daniel Morgan (danmorg@sc.rr.com)
-//
-// (C) Ximian, Inc. 2002
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Data;
-using System.Data.Common;
-
-namespace Mono.Data.MySql
-{
- /// <summary>
- /// Represents a transaction to be performed on a SQL database.
- /// </summary>
- public sealed class MySqlTransaction : MarshalByRefObject,
- IDbTransaction, IDisposable
- {
- #region Fields
-
- private bool doingTransaction = false;
- private MySqlConnection conn = null;
- private IsolationLevel isolationLevel =
- IsolationLevel.ReadCommitted;
- // FIXME: What is the default isolation level for MySQL?
-
- private bool disposed = false;
-
- #endregion
-
- #region Public Methods
-
- [MonoTODO]
- public void Commit ()
- {
- if(doingTransaction == false)
- throw new InvalidOperationException(
- "Begin transaction was not " +
- "done earlier " +
- "thus PostgreSQL can not " +
- "Commit transaction.");
-
- MySqlCommand cmd = new MySqlCommand("COMMIT", conn);
- cmd.ExecuteNonQuery();
-
- doingTransaction = false;
- }
-
- [MonoTODO]
- public void Rollback()
- {
- if(doingTransaction == false)
- throw new InvalidOperationException(
- "Begin transaction was not " +
- "done earlier " +
- "thus PostgreSQL can not " +
- "Rollback transaction.");
-
- MySqlCommand cmd = new MySqlCommand("ROLLBACK", conn);
- cmd.ExecuteNonQuery();
-
- doingTransaction = false;
- }
-
- // For MySQL, Rollback(string) will not be implemented
- // because MySQL does not support Savepoints
- [Obsolete]
- public void Rollback(string transactionName) {
- // throw new NotImplementedException ();
- Rollback();
- }
-
- // For MySQL, Save(string) will not be implemented
- // because MySQL does not support Savepoints
- [Obsolete]
- public void Save (string savePointName) {
- // throw new NotImplementedException ();
- }
-
- #endregion // Public Methods
-
- #region Internal Methods to Mono.Data.MySql Assembly
-
- internal void Begin()
- {
- if(doingTransaction == true)
- throw new InvalidOperationException(
- "Transaction has begun " +
- "and MySQL does not " +
- "support nested transactions.");
-
- MySqlCommand cmd = new MySqlCommand("BEGIN", conn);
- cmd.ExecuteNonQuery();
-
- doingTransaction = true;
- }
-
- internal void SetIsolationLevel(IsolationLevel isoLevel)
- {
- String sSql = "SET TRANSACTION ISOLATION LEVEL ";
-
- switch (isoLevel) {
- case IsolationLevel.ReadCommitted:
- sSql += "READ COMMITTED";
- break;
- case IsolationLevel.ReadUncommitted:
- sSql += "READ UNCOMMITTED";
- break;
- case IsolationLevel.RepeatableRead:
- sSql += "REPEATABLE READ";
- break;
- case IsolationLevel.Serializable:
- sSql += "SERIALIZABLE";
- break;
- default:
- // generate exception here for anything else
- break;
- }
- MySqlCommand cmd = new MySqlCommand(sSql, conn);
- cmd.ExecuteNonQuery();
-
- this.isolationLevel = isoLevel;
- }
-
- internal void SetConnection(MySqlConnection connection)
- {
- this.conn = connection;
- }
-
- #endregion // Internal Methods to System.Data.dll Assembly
-
- #region Properties
-
- IDbConnection IDbTransaction.Connection {
- get {
- return Connection;
- }
- }
-
- public MySqlConnection Connection {
- get {
- return conn;
- }
- }
-
- public IsolationLevel IsolationLevel {
- get {
- return isolationLevel;
- }
- }
-
- internal bool DoingTransaction {
- get {
- return doingTransaction;
- }
- }
-
- #endregion Properties
-
- #region Destructors
-
- // Destructors aka Finalize and Dispose
-
- private void Dispose(bool disposing) {
- if(!this.disposed) {
- if(disposing) {
- // release any managed resources
- conn = null;
- }
- // release any unmanaged resources
-
- // close any handles
- this.disposed = true;
- }
- }
-
- void IDisposable.Dispose() {
- Dispose(true);
- }
-
- // aka Finalize
- ~MySqlTransaction() {
- Dispose (false);
- }
- #endregion // Destructors
-
- }
-}
+++ /dev/null
-//
-// MySqlTypes.cs - enums, classes, and structs for handling MySql Types
-//
-// Assembly: Mono.Data.MySql.dll
-// Namespace: Mono.Data.MySql
-//
-// Author:
-// Daniel Morgan <danmorg@sc.rr.com>
-//
-// (c)copyright 2002 Daniel Morgan
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;\r
-using System.Collections;\r
-using System.Data;\r
-using System.Data.Common;\r
-using System.Text;\r
-
-namespace Mono.Data.MySql {
- internal enum MySqlEnumFieldTypes {
- FIELD_TYPE_DECIMAL,
- FIELD_TYPE_TINY,
- FIELD_TYPE_SHORT,
- FIELD_TYPE_LONG,
- FIELD_TYPE_FLOAT,
- FIELD_TYPE_DOUBLE,
- FIELD_TYPE_NULL,
- FIELD_TYPE_TIMESTAMP,
- FIELD_TYPE_LONGLONG,
- FIELD_TYPE_INT24,
- FIELD_TYPE_DATE,
- FIELD_TYPE_TIME,
- FIELD_TYPE_DATETIME,
- FIELD_TYPE_YEAR,
- FIELD_TYPE_NEWDATE,
- FIELD_TYPE_ENUM=247,
- FIELD_TYPE_SET=248,
- FIELD_TYPE_TINY_BLOB=249,
- FIELD_TYPE_MEDIUM_BLOB=250,
- FIELD_TYPE_LONG_BLOB=251,
- FIELD_TYPE_BLOB=252,
- FIELD_TYPE_VAR_STRING=253,
- FIELD_TYPE_STRING=254
- }
-
- sealed internal class MySqlHelper {
-
- public static string GetMySqlTypeName(MySqlEnumFieldTypes mysqlFieldType) {
-
- string typeName;
-
- switch(mysqlFieldType) {
- case MySqlEnumFieldTypes.FIELD_TYPE_DECIMAL:
- typeName = "decimal";
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_TINY:
- typeName = "tiny";
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_SHORT:
- typeName = "short";
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_LONG:
- typeName = "long";
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_FLOAT:
- typeName = "float";
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_DOUBLE:
- typeName = "double";
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_NULL:
- typeName = "null";
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_TIMESTAMP:
- typeName = "timestamp";
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_LONGLONG:
- typeName = "longlong";
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_INT24:
- typeName = "int24";
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_DATE:
- typeName = "date";
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_TIME:
- typeName = "time";
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_DATETIME:
- typeName = "datetime";
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_YEAR:
- typeName = "year";
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_NEWDATE:
- typeName = "newdate";
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_ENUM:
- typeName = "enum";
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_SET:
- typeName = "set";
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_TINY_BLOB:
- typeName = "tinyblob";
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_MEDIUM_BLOB:
- typeName = "mediumblob";
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_LONG_BLOB:
- typeName = "longblob";
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_BLOB:
- typeName = "blob";
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_VAR_STRING:
- typeName = "varchar";
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_STRING:
- typeName = "char";
- break;
- default:
- typeName = "text";
- break;
- }
- return typeName;
- }
-
- public static DbType MySqlTypeToDbType(MySqlEnumFieldTypes mysqlFieldType) {
- DbType dbType;
-
- // FIXME: verify these translation are correct
-
- switch(mysqlFieldType) {
- case MySqlEnumFieldTypes.FIELD_TYPE_DECIMAL:
- dbType = DbType.Decimal;
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_TINY:
- dbType = DbType.Int16;
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_SHORT:
- dbType = DbType.Int16;
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_LONG:
- dbType = DbType.Int32;
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_FLOAT:
- dbType = DbType.Single;
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_DOUBLE:
- dbType = DbType.Double;
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_NULL:
- dbType = DbType.String;
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_TIMESTAMP:
- dbType = DbType.String;
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_LONGLONG:
- dbType = DbType.Int64;
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_INT24:
- dbType = DbType.Int64;
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_DATE:
- dbType = DbType.Date;
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_TIME:
- dbType = DbType.Time;
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_DATETIME:
- dbType = DbType.DateTime;
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_YEAR:
- dbType = DbType.Int16;
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_NEWDATE:
- dbType = DbType.Date;
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_ENUM:
- dbType = DbType.Int32;
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_SET:
- dbType = DbType.String;
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_TINY_BLOB:
- case MySqlEnumFieldTypes.FIELD_TYPE_MEDIUM_BLOB:
- case MySqlEnumFieldTypes.FIELD_TYPE_LONG_BLOB:
- case MySqlEnumFieldTypes.FIELD_TYPE_BLOB:
- dbType = DbType.Binary;
- break;
- case MySqlEnumFieldTypes.FIELD_TYPE_VAR_STRING:
- case MySqlEnumFieldTypes.FIELD_TYPE_STRING:
- dbType = DbType.String;
- break;
- default:
- dbType = DbType.String;
- break;
- }
-
- return dbType;
- }
-
- // Translates System.Data.DbType to System.Type
- public static Type DbTypeToSystemType (DbType dType) {
-
- Type typ = null;
-
- switch(dType) {
- case DbType.String:
- typ = typeof(String);
- break;
- case DbType.Boolean:
- typ = typeof(Boolean);
- break;
- case DbType.Int16: \r
- typ = typeof(Int16);\r
- break;\r
- case DbType.Int32:\r
- typ = typeof(Int32);\r
- break;\r
- case DbType.Int64:\r
- typ = typeof(Int64);\r
- break;\r
- case DbType.Decimal:\r
- typ = typeof(Decimal);\r
- break;\r
- case DbType.Single:\r
- typ = typeof(Single);\r
- break;\r
- case DbType.Double:\r
- typ = typeof(Double);\r
- break;\r
- case DbType.Date:\r
- case DbType.Time:\r
- case DbType.DateTime:\r
- typ = typeof(DateTime);\r
- break;\r
- default:\r
- typ = typeof(String);\r
- break;\r
- }
- return typ;
- }
-
- // Converts data value from database to .NET System type.\r
- public static object ConvertDbTypeToSystem (MySqlEnumFieldTypes mysqlFieldType,
- DbType typ, String myValue) {
-
- object obj = null;
-
- //Console.WriteLine("DEBUG: ConvertDbTypeToSystem: " + myValue);
-
- // FIXME: how do you handle NULL and "" for MySQL correctly?
- if(myValue == null) {
- return DBNull.Value;
- }
- else if(myValue.Equals("")) {
- return DBNull.Value;
- }
-
- switch(mysqlFieldType) {
- case MySqlEnumFieldTypes.FIELD_TYPE_TIMESTAMP:
- if(myValue.Equals("00000000000000"))
- return DBNull.Value;
- break;
- }
-
- // Date, Time, and DateTime
- // are parsed based on ISO format
- // "YYYY-MM-DD hh:mi:ss"
-
- switch(typ) {
- case DbType.String:
- obj = String.Copy(myValue);
- break;
- case DbType.Boolean:
- obj = myValue.Equals("t");
- break;
- case DbType.Int16:\r
- obj = Int16.Parse(myValue);\r
- break;\r
- case DbType.Int32:\r
- obj = Int32.Parse(myValue);\r
- break;\r
- case DbType.Int64:\r
- obj = Int64.Parse(myValue);\r
- break;\r
- case DbType.Decimal:\r
- obj = Decimal.Parse(myValue);\r
- break;\r
- case DbType.Single:\r
- obj = Single.Parse(myValue);\r
- break;\r
- case DbType.Double:\r
- obj = Double.Parse(myValue);\r
- break;\r
- case DbType.Date:\r
- String[] sd = myValue.Split(new Char[] {'-'});\r
- obj = new DateTime(\r
- Int32.Parse(sd[0]), Int32.Parse(sd[1]), Int32.Parse(sd[2]),\r
- 0,0,0);\r
- break;\r
- case DbType.Time:\r
- String[] st = myValue.Split(new Char[] {':'});\r
- obj = new DateTime(0001,01,01,\r
- Int32.Parse(st[0]),Int32.Parse(st[1]),Int32.Parse(st[2]));\r
- break;\r
- case DbType.DateTime:\r
- Int32 YYYY,MM,DD,hh,mi,ss;\r
- YYYY = Int32.Parse(myValue.Substring(0,4));\r
- MM = Int32.Parse(myValue.Substring(5,2));\r
- DD = Int32.Parse(myValue.Substring(8,2));\r
- hh = Int32.Parse(myValue.Substring(11,2));\r
- mi = Int32.Parse(myValue.Substring(14,2));\r
- ss = Int32.Parse(myValue.Substring(17,2));\r
- obj = new DateTime(YYYY,MM,DD,hh,mi,ss,0);\r
- break;\r
- default:\r
- obj = String.Copy(myValue);\r
- break;\r
- }
-
- return obj;
- }
-
- // FIXME: handle NULLs correctly in MySQL
- public static string DBNullObjectToString(DbType dbtype) {
-
- string s = "";
-
- const string NullString = "''";
- const string Null = "NULL";
-
- switch(dbtype) {\r
- case DbType.String:
- s = NullString;
- break;
- case DbType.Boolean:
- s = NullString;
- break;
- case DbType.Int16:\r
- s = Null;\r
- break;\r
- case DbType.Int32:\r
- s = Null;\r
- break;\r
- case DbType.Int64:\r
- s = Null;\r
- break;\r
- case DbType.Decimal:\r
- s = Null;\r
- break;\r
- case DbType.Single:\r
- s = Null;\r
- break;\r
- case DbType.Double:\r
- s = Null;\r
- break;\r
- case DbType.Date:\r
- s = NullString;\r
- break;\r
- case DbType.Time:\r
- s = NullString;\r
- break;\r
- case DbType.DateTime:\r
- s = NullString;\r
- break;\r
- default:\r
- // default to DbType.String\r
- s = NullString;\r
- break;\r
- }
-
- return s;
- }
-
- // Convert a .NET System value type (Int32, String, Boolean, etc)
- // to a string that can be included within a SQL statement.
- // This is to methods provides the parameters support
- // for the MySQL .NET Data provider
- public static string ObjectToString(DbType dbtype, object obj) {\r
- \r
- string s = "";\r
-\r
- // FIXME: how do we handle NULLs?\r
- // code is untested\r
- if(obj.Equals(DBNull.Value)) {\r
- return DBNullObjectToString(dbtype);\r
- }\r
-\r
- // Date, Time, and DateTime are expressed in ISO format\r
- // which is "YYYY-MM-DD hh:mm:ss.ms";\r
- DateTime dt;\r
- StringBuilder sb;\r
-\r
- const string zero = "0";\r
-\r
- switch(dbtype) {\r
- case DbType.String:
- s = "'" + obj + "'";
- break;
- case DbType.Boolean:
- if((bool)obj == true)
- s = "'t'";
- else
- s = "'f'";
- break;
- case DbType.Int16:\r
- s = obj.ToString();\r
- break;\r
- case DbType.Int32:\r
- s = obj.ToString();\r
- break;\r
- case DbType.Int64:\r
- s = obj.ToString();\r
- break;\r
- case DbType.Decimal:\r
- s = obj.ToString();\r
- break;\r
- case DbType.Single:\r
- s = obj.ToString();\r
- break;\r
- case DbType.Double:\r
- s = obj.ToString();\r
- break;\r
- case DbType.Date:\r
- dt = (DateTime) obj;\r
- sb = new StringBuilder();\r
- sb.Append('\'');\r
- // year\r
- if(dt.Year < 10)\r
- sb.Append("000" + dt.Year);\r
- else if(dt.Year < 100)\r
- sb.Append("00" + dt.Year);\r
- else if(dt.Year < 1000)\r
- sb.Append("0" + dt.Year);\r
- else\r
- sb.Append(dt.Year);\r
- sb.Append("-");\r
- // month\r
- if(dt.Month < 10)\r
- sb.Append(zero + dt.Month);\r
- else\r
- sb.Append(dt.Month);\r
- sb.Append("-");\r
- // day\r
- if(dt.Day < 10)\r
- sb.Append(zero + dt.Day);\r
- else\r
- sb.Append(dt.Day);\r
- sb.Append('\'');\r
- s = sb.ToString();\r
- break;\r
- case DbType.Time:\r
- dt = (DateTime) obj;\r
- sb = new StringBuilder();\r
- sb.Append('\'');\r
- // hour\r
- if(dt.Hour < 10)\r
- sb.Append(zero + dt.Hour);\r
- else\r
- sb.Append(dt.Hour);\r
- sb.Append(":");\r
- // minute\r
- if(dt.Minute < 10)\r
- sb.Append(zero + dt.Minute);\r
- else\r
- sb.Append(dt.Minute);\r
- sb.Append(":");\r
- // second\r
- if(dt.Second < 10)\r
- sb.Append(zero + dt.Second);\r
- else\r
- sb.Append(dt.Second);\r
- sb.Append('\'');\r
- s = sb.ToString();\r
- break;\r
- case DbType.DateTime:\r
- dt = (DateTime) obj;\r
- sb = new StringBuilder();\r
- sb.Append('\'');\r
- // year\r
- if(dt.Year < 10)\r
- sb.Append("000" + dt.Year);\r
- else if(dt.Year < 100)\r
- sb.Append("00" + dt.Year);\r
- else if(dt.Year < 1000)\r
- sb.Append("0" + dt.Year);\r
- else\r
- sb.Append(dt.Year);\r
- sb.Append("-");\r
- // month\r
- if(dt.Month < 10)\r
- sb.Append(zero + dt.Month);\r
- else\r
- sb.Append(dt.Month);\r
- sb.Append("-");\r
- // day\r
- if(dt.Day < 10)\r
- sb.Append(zero + dt.Day);\r
- else\r
- sb.Append(dt.Day);\r
- sb.Append(" ");\r
- // hour\r
- if(dt.Hour < 10)\r
- sb.Append(zero + dt.Hour);\r
- else\r
- sb.Append(dt.Hour);\r
- sb.Append(":");\r
- // minute\r
- if(dt.Minute < 10)\r
- sb.Append(zero + dt.Minute);\r
- else\r
- sb.Append(dt.Minute);\r
- sb.Append(":");\r
- // second\r
- if(dt.Second < 10)\r
- sb.Append(zero + dt.Second);\r
- else\r
- sb.Append(dt.Second);\r
- sb.Append('\'');\r
- s = sb.ToString();\r
- break;\r
- default:\r
- // default to DbType.String\r
- s = "'" + obj + "'";\r
- break;\r
- }
- return s;
- }
- }
-}
+++ /dev/null
-//
-// TODOAttribute.cs
-//
-// Author:
-// Ravi Pratap (ravi@ximian.com)
-//
-// (C) Ximian, Inc. http://www.ximian.com
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-
-namespace Mono.Data.MySql {
-
- /// <summary>
- /// The TODO attribute is used to flag all incomplete bits in our class libraries
- /// </summary>
- ///
- /// <remarks>
- /// Use this to decorate any element which you think is not complete
- /// </remarks>
- [AttributeUsage (AttributeTargets.All)]
- internal class MonoTODOAttribute : Attribute {
-
- string comment;
-
- public MonoTODOAttribute ()
- {}
-
- public MonoTODOAttribute (string comment)
- {
- this.comment = comment;
- }
-
- public string Comment {
- get { return comment; }
- }
- }
-}
+++ /dev/null
-//
-// Test.cs
-//
-// Used to Test the C# bindings to MySQL. This test
-// is based on the test that comes with MySQL.
-// Part of the C# bindings to MySQL library libMySQL.dll
-//
-// Author:
-// Brad Merrill <zbrad@cybercom.net>
-//
-// (C)Copyright 2002 Brad Merril
-//
-// http://www.cybercom.net/~zbrad/DotNet/MySql/
-//
-// Mono has gotten permission from Brad Merrill to include in
-// the Mono Class Library
-// his C# bindings to MySQL under the X11 License
-//
-// Mono can be found at http://www.go-mono.com/
-// The X11/MIT License can be found
-// at http://www.opensource.org/licenses/mit-license.html
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Runtime.InteropServices;
-using Mono.Data.MySql;
-
-///<remarks>
-///<para>
-/// MySql P/Invoke implementation test program
-/// Brad Merrill
-/// 3-Mar-2002
-///</para>
-///<para>
-/// This is based on the myTest.c program in the
-/// libmysqltest example directory of the mysql distribution.
-///</para>
-///<para>
-/// I noticed during implementation that the C api libraries are
-/// thread sensitive, in that they store information in the
-/// currently executing thread local storage. This is
-/// incompatible with the thread pool model in the CLR, in which
-/// you could be executing the same context on different
-/// threads.
-///</para>
-///<para>
-/// A better implementation would be to rewrite the libmysql
-/// layer in managed code, and do all the socket APIs, and mysql
-/// protocol using the .NET Framework APIs. However, that's a
-/// bit more than a weekend of work.
-///</para>
-///</remarks>
-public class Test {
- [STAThread]
- public static int Main() {
- Console.WriteLine("Test for MySQL C# Bindings started...");
- Console.Out.Flush();
- int rcq;
-
- string myDb = "test";
- string myStmt = "SELECT * FROM sometable";
- string insertStmt = "INSERT INTO SOMETABLE (TID,TDESC,AINT) VALUES ('MySQL','Mono.Data',12)";
-
- Console.WriteLine("MySql Init...");
- Console.Out.Flush();
- IntPtr db = MySql.Init(IntPtr.Zero);
- if (db == IntPtr.Zero) {
- Console.WriteLine("Error: Init failed.");
- Console.Out.Flush();
- return 1;
- }
-
- Console.WriteLine("MySql Connection...");
- Console.Out.Flush();
- IntPtr conn = MySql.Connect(db, "", "", "", "", MySql.Port,
- "", (uint)0);
- //IntPtr conn = MySql.mysql_connect(db, null, null, null, null, MySql.Port,
- // null, (uint)0);
- if (conn == IntPtr.Zero) {
- Console.WriteLine("Error: Connect failed.");
- Console.Out.Flush();
- Console.WriteLine("MySql Error: " + MySql.Error(db));
- Console.Out.Flush();
- return 1;
- }
-
- Console.WriteLine("MySql Selecting Database: " + myDb + "...");
- Console.Out.Flush();
- int sdb = MySql.SelectDb(db, myDb);
- if (sdb != 0) {
- Console.WriteLine("Error: Can not select the "+myDb+" database.");
- Console.Out.Flush();
- Console.WriteLine("MySql Error: " + MySql.Error(db));
- Console.Out.Flush();
- return 1;
- }
-
- Console.WriteLine("Insert SQL: "+insertStmt);
- Console.Out.Flush();
- rcq = MySql.Query(db, insertStmt);
- if (rcq != 0) {
- Console.WriteLine("Couldn't execute ["+insertStmt+"] on server.");
- Console.Out.Flush();
- Console.WriteLine("MySql Error: " + MySql.Error(db));
- Console.Out.Flush();
- return 1;
- }
-
- Console.WriteLine("Query: "+myStmt);
- Console.Out.Flush();
- rcq = MySql.Query(db, myStmt);
- if (rcq != 0) {
- Console.WriteLine("?Couldn't execute ["+myStmt+"] on server.");
- Console.Out.Flush();
- Console.WriteLine("MySql Error: " + MySql.Error(db));
- Console.Out.Flush();
- return 1;
- }
-
- Console.WriteLine("Process Results...");
- Console.Out.Flush();
- procResults(db);
-
- Console.WriteLine("==== Diagnostic info ====");
- Console.Out.Flush();
- Console.WriteLine("Client info: "+MySql.GetClientInfo());
- Console.WriteLine("Host info: "+MySql.GetHostInfo(db));
- Console.WriteLine("Server info: "+MySql.GetServerInfo(db));
- Console.Out.Flush();
-
- Console.WriteLine("List Processes...");
- Console.Out.Flush();
- listProcesses(db);
- Console.WriteLine("List Tables...");
- Console.Out.Flush();
- listTables(db);
-
- Console.WriteLine("MySql Stat...");
- Console.Out.Flush();
- Console.WriteLine(MySql.Stat(db));
-
- Console.WriteLine("MySql Close...");
- Console.Out.Flush();
- MySql.Close(db);
-
- Console.WriteLine("MySql Thread End...");
- Console.Out.Flush();
- MySql.ThreadEnd();
-
- Console.WriteLine("Exiting...");
- Console.Out.Flush();
-
- return 0;
- }
-
- static void procResults(IntPtr db) {
- IntPtr res = MySql.StoreResult(db);
- int numRows = MySql.NumRows(res);
- Console.WriteLine("Number of records found: " + numRows);
- int numFields = MySql.NumFields(res);
- string[] fields = new string[numFields];
- for (int i = 0; i < numFields; i++) {
- Field fd = (Field) Marshal.PtrToStructure(MySql.FetchField(res), typeof(Field));
- fields[i] = fd.Name;
- }
- IntPtr row;
- int recCnt = 1;
- while ((row = MySql.FetchRow(res)) != IntPtr.Zero) {
- Console.WriteLine("Record #" + recCnt + ":");
- for (int i = 0, j = 1; i < numFields; i++, j++) {
- Console.WriteLine(" theField[[[" + fields[i] + "]]]\n");
- Console.Out.Flush();
- Console.WriteLine(" Fld #"+j+" ("+fields[i]+"): "+rowVal(row, i));
- Console.Out.Flush();
- }
- Console.WriteLine("==============================");
- }
- MySql.FreeResult(res);
- }
-
- static string rowVal(IntPtr res, int index) {
- IntPtr str = Marshal.ReadIntPtr(res, index*IntPtr.Size);
- if (str == IntPtr.Zero)
- return "NULL";
- string s = Marshal.PtrToStringAnsi(str);
- return s;
- }
-
- static void listProcesses(IntPtr db) {
- IntPtr res = MySql.ListProcesses(db);
- if (res == IntPtr.Zero) {
- Console.WriteLine("Got error "+MySql.Error(db)+" when retreiving processlist");
- return;
- }
- int numRows = MySql.NumRows(res);
- Console.WriteLine("Number of records found: " + numRows);
- int numFields = MySql.NumFields(res);
- string[] fields = new string[numFields];
- for (int i = 0; i < numFields; i++) {
- Field fd = (Field) Marshal.PtrToStructure(MySql.FetchField(res), typeof(Field));
- fields[i] = fd.Name;
- }
- IntPtr row;
- int recCnt = 1;
- while ((row = MySql.FetchRow(res)) != IntPtr.Zero) {
- Console.WriteLine("Process #" + recCnt + ":");
- for (int i = 0, j = 1; i < numFields; i++, j++) {
- Console.WriteLine(" Fld #"+j+" ("+fields[i]+"): "+rowVal(row, i));
- }
- Console.WriteLine("==============================");
- }
- MySql.FreeResult(res);
- }
-
- static void listTables(IntPtr db) {
- IntPtr res = MySql.ListTables(db, "%");
- if (res == IntPtr.Zero)
- return;
- int numRows = MySql.NumRows(res);
- Console.WriteLine("Number of records found: " + numRows);
- int numFields = MySql.NumFields(res);
- string[] fields = new string[numFields];
- for (int i = 0; i < numFields; i++) {
- Field fd = (Field) Marshal.PtrToStructure(MySql.FetchField(res), typeof(Field));
- fields[i] = fd.Name;
- }
- IntPtr row;
- int recCnt = 1;
- while ((row = MySql.FetchRow(res)) != IntPtr.Zero) {
- Console.WriteLine("Process #" + recCnt + ":");
- for (int i = 0, j = 1; i < numFields; i++, j++) {
- Console.WriteLine(" Fld #"+j+" ("+fields[i]+"): "+rowVal(row, i));
- }
- Console.WriteLine("==============================");
- }
- MySql.FreeResult(res);
- }
-}
+++ /dev/null
-/* MySqlTest.cs - based on PostgresTest.cs which is based
- * on postgres-test.c in libgda
- *
- * Copyright (C) 2002 Gonzalo Paniagua Javier
- * Copyright (C) 2002 Daniel Morgan
- *
- * ORIGINAL AUTHOR:
- * Gonzalo Paniagua Javier <gonzalo@gnome-db.org>
- * PORTING FROM C TO C# AUTHOR:
- * Daniel Morgan <danmorg@sc.rr.com>
- *
- * Permission was given from the original author, Gonzalo Paniagua Javier,
- * to port and include his original work in Mono.
- *
- * The original work falls under the LGPL, but the port to C# falls
- * under the X11 license.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program; see the file COPYING. If not,
- * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-//
-// To compile on Windows using Cygwin, you will need to do:
-// mono C:/cygwin/home/danmorg/mono/install/bin/mcs.exe MySqlTest.cs -r System.Data.dll -r Mono.Data.MySql.dll
-//
-
-using System;
-using System.Data;
-using System.Data.Common;
-using Mono.Data.MySql;
-
-namespace Test.Mono.Data.MySql {
-
- public class MySqlTest {
-
- // execute SQL CREATE TABLE Command using ExecuteNonQuery()
- public static void CreateTable (IDbConnection cnc) {
-
- IDbCommand createCommand = cnc.CreateCommand();
-
- createCommand.CommandText =
- "CREATE TABLE mono_mysql_test (" +
- "tinyint_value TINYINT," +\r
- "smallint_value SMALLINT," +\r
- "mediumint_value MEDIUMINT," +\r
- "int_value INT," +\r
- "integer_value INTEGER," +\r
- "bigint_value BIGINT," + \r
- "real_value REAL," + \r
- "double_value DOUBLE," + \r
- "float_value FLOAT," +\r
- "decimal_value DECIMAL(8,2)," + \r
- "numeric_value NUMERIC(15,2)," + \r
- "char_value CHAR(2)," + \r
- "varchar_value VARCHAR(5)," + \r
- "date_value DATE," + \r
- "time_value TIME," +\r
- "timestamp_value TIMESTAMP," +\r
- "datetime_value DATETIME," +\r
- "tinyblob_value TINYBLOB," +\r
- "blob_value BLOB," +\r
- "mediumblob_value MEDIUMBLOB," +\r
- "longblob_value LONGBLOB," +\r
- "tinytext_value TINYTEXT," +\r
- "text_value TEXT," +\r
- "mediumtext_value MEDIUMTEXT," +\r
- "longtext_value LONGTEXT," +\r
- "enum_value ENUM('dog','cat','bird','fish')," +\r
- "set_value SET('value1','value2','value3','value4'), " +\r
- "null_tinyint_value TINYINT," +\r
- "null_smallint_value SMALLINT," +\r
- "null_mediumint_value MEDIUMINT," +\r
- "null_int_value INT," +\r
- "null_integer_value INTEGER," +\r
- "null_bigint_value BIGINT," + \r
- "null_real_value REAL," + \r
- "null_double_value DOUBLE," + \r
- "null_float_value FLOAT," +\r
- "null_decimal_value DECIMAL(8,2)," + \r
- "null_numeric_value NUMERIC(15,2)," + \r
- "null_char_value CHAR(2)," + \r
- "null_varchar_value VARCHAR(5)," + \r
- "null_date_value DATE," + \r
- "null_time_value TIME," +\r
- "null_timestamp_value TIMESTAMP," +\r
- "null_datetime_value DATETIME," +\r
- "null_tinyblob_value TINYBLOB," +\r
- "null_blob_value BLOB," +\r
- "null_mediumblob_value MEDIUMBLOB," +\r
- "null_longblob_value LONGBLOB," +\r
- "null_tinytext_value TINYTEXT," +\r
- "null_text_value TEXT," +\r
- "null_mediumtext_value MEDIUMTEXT," +\r
- "null_longtext_value LONGTEXT," +\r
- "null_enum_value ENUM('dog','cat','bird','fish')," +\r
- "null_set_value SET('value1','value2','value3','value4') " +\r
- ") ";
-
- int rowsAffected;
- rowsAffected = createCommand.ExecuteNonQuery ();
- Console.WriteLine("Rows Affected: " + rowsAffected);
- }
-
- // execute SQL DROP TABLE Command using ExecuteNonQuery
- public static void DropTable (IDbConnection cnc) {
-
- IDbCommand dropCommand = cnc.CreateCommand ();
-
- dropCommand.CommandText =
- "DROP TABLE mono_mysql_test";
-
- int rowsAffected;
- rowsAffected = dropCommand.ExecuteNonQuery ();
- Console.WriteLine("Rows Affected: " + rowsAffected);
-
- }
-
- // execute stored procedure using ExecuteScalar()
- public static object CallStoredProcedure (IDbConnection cnc) {
-
- IDbCommand callStoredProcCommand = cnc.CreateCommand ();
- object data;
-
- callStoredProcCommand.CommandType =
- CommandType.StoredProcedure;
- callStoredProcCommand.CommandText =
- "version";
-
- data = callStoredProcCommand.ExecuteScalar ();
-
- return data;
- }
-
- // execute SQL INSERT Command using ExecuteNonQuery()
- public static void InsertData (IDbConnection cnc) {
-
- IDbCommand insertCommand = cnc.CreateCommand();
-
- insertCommand.CommandText =
- "INSERT INTO mono_mysql_test (" +
- "tinyint_value," +\r
- "smallint_value," +\r
- "mediumint_value," +\r
- "int_value," +\r
- "integer_value," +\r
- "bigint_value," + \r
- "real_value," + \r
- "double_value," + \r
- "float_value," +\r
- "decimal_value," + \r
- "numeric_value," + \r
- "char_value," + \r
- "varchar_value," + \r
- "date_value," + \r
- "time_value," +\r
- "timestamp_value," +\r
- "datetime_value," +\r
- "tinyblob_value," +\r
- "blob_value," +\r
- "mediumblob_value," +\r
- "longblob_value," +\r
- "tinytext_value," +\r
- "text_value," +\r
- "mediumtext_value," +\r
- "longtext_value," +\r
- "enum_value," +\r
- "set_value " +
- ") VALUES (" +
- "1,2,3,4,5,6, " +
- "1.1, 2.2, 3.3, " +
- "10.10, 11.11, " +
- "'AB','mono'," +
- "'2002-12-31', '11:15:07'," +
- "'20021231111507', '2002-12-31 11:15:07'," +
- "'fe','fi','fo','thumb','i','smell','some','food'," +
- "'cat', 'value2,value3' " +
- ")";
-
- int rowsAffected;
- rowsAffected = insertCommand.ExecuteNonQuery ();
- Console.WriteLine("Rows Affected: " + rowsAffected);
- }
-
- // execute a SQL SELECT Query using ExecuteReader() to retrieve
- // a IDataReader so we retrieve data
- public static IDataReader SelectData (IDbConnection cnc) {
-
- IDbCommand selectCommand = cnc.CreateCommand();
- IDataReader reader;
-
- // FIXME: System.Data classes need to handle NULLs
- // this would be done by System.DBNull ?
- // FIXME: System.Data needs to handle more data types
-
- selectCommand.CommandText =
- "SELECT * " +
- "FROM mono_mysql_test";
-
- reader = selectCommand.ExecuteReader ();
-
- return reader;
- }
-
- // Tests a SQL Command (INSERT, UPDATE, DELETE)
- // executed via ExecuteReader
- public static IDataReader SelectDataUsingInsertCommand (IDbConnection cnc) {
-
- IDbCommand selectCommand = cnc.CreateCommand();
- IDataReader reader;
-
- // This is a SQL INSERT Command, not a Query
- selectCommand.CommandText =
- "INSERT INTO mono_mysql_test (" +
- "tinyint_value," +\r
- "smallint_value," +\r
- "mediumint_value," +\r
- "int_value," +\r
- "integer_value," +\r
- "bigint_value," + \r
- "real_value," + \r
- "double_value," + \r
- "float_value," +\r
- "decimal_value," + \r
- "numeric_value," + \r
- "char_value," + \r
- "varchar_value," + \r
- "date_value," + \r
- "time_value," +\r
- "timestamp_value," +\r
- "datetime_value," +\r
- "tinyblob_value," +\r
- "blob_value," +\r
- "mediumblob_value," +\r
- "longblob_value," +\r
- "tinytext_value," +\r
- "text_value," +\r
- "mediumtext_value," +\r
- "longtext_value," +\r
- "enum_value," +\r
- "set_value " +
- ") VALUES (" +
- "91,92,93,94,95,96, " +
- "91.1, 92.2, 93.3, " +
- "910.10, 911.11, " +
- "'CD','mcs'," +
- "'2003-11-23', '10:24:45'," +
- "'20031123122445', '2003-11-23 10:24:45'," +
- "'ack','bleh','heh','pop','me','nope','yeah','fun'," +
- "'dog', 'value1,value3,value4' " +
- ")";
-
- reader = selectCommand.ExecuteReader ();
-
- return reader;
- }
-
- // Tests a SQL Command not (INSERT, UPDATE, DELETE)
- // executed via ExecuteReader
- public static IDataReader SelectDataUsingCommand (IDbConnection cnc) {
-
- IDbCommand selectCommand = cnc.CreateCommand();
- IDataReader reader;
-
- // This is a SQL Command, not a Query
- selectCommand.CommandText =
- "SET AUTOCOMMIT=0";
-
- reader = selectCommand.ExecuteReader ();
-
- return reader;
- }
-
-
- // execute an SQL UPDATE Command using ExecuteNonQuery()
- public static void UpdateData (IDbConnection cnc) {
-
- IDbCommand updateCommand = cnc.CreateCommand();
-
- updateCommand.CommandText =
- "UPDATE mono_mysql_test " +
- "SET " +
- "int_value = 777 " +
- "WHERE char_value = 'AB'";
-
- updateCommand.ExecuteNonQuery ();
- }
-
- // used to do a min(), max(), count(), sum(), or avg()
- // execute SQL SELECT Query using ExecuteScalar
- public static object SelectAggregate (IDbConnection cnc, String agg) {
-
- IDbCommand selectCommand = cnc.CreateCommand();
- object data;
-
- Console.WriteLine("Aggregate: " + agg);
-
- selectCommand.CommandType = CommandType.Text;
- selectCommand.CommandText =
- "SELECT " + agg +
- "FROM mono_mysql_test";
-
- data = selectCommand.ExecuteScalar ();
-
- Console.WriteLine("Agg Result: " + data);
-
- return data;
- }
-
- // used internally by ReadData() to read each result set
- public static void ReadResult(IDataReader rdr, DataTable dt) {
- \r
- // number of columns in the table\r
- Console.WriteLine(" Total Columns: " +\r
- dt.Rows.Count);\r
-\r
- // display the schema\r
- string colName;\r
- string colValue;\r
- foreach (DataRow schemaRow in dt.Rows) {\r
- foreach (DataColumn schemaCol in dt.Columns) {\r
- colName = schemaCol.ColumnName;\r
- colValue = (schemaRow[schemaCol]).ToString();\r
- Console.WriteLine(colName + " = " + colValue);\r
- }\r
- Console.WriteLine();\r
- }\r
-\r
- int nRows = 0;\r
- int c = 0;\r
- string output, metadataValue, dataValue;\r
- // Read and display the rows\r
- Console.WriteLine("Gonna do a Read() now...");\r
- while(rdr.Read()) {\r
- Console.WriteLine(" Row " + nRows + ": ");\r
- \r
- for(c = 0; c < rdr.FieldCount; c++) {\r
- // column meta data \r
- metadataValue = \r
- " Col " + \r
- c + ": " + \r
- rdr.GetName(c);\r
- \r
- // column data\r
- if(rdr.IsDBNull(c) == true)\r
- dataValue = " is NULL";\r
- else\r
- dataValue = \r
- ": " + \r
- rdr.GetValue(c).ToString();\r
- \r
- // display column meta data and data\r
- output = metadataValue + dataValue; \r
- Console.WriteLine(output);\r
- }\r
- nRows++;\r
- }\r
- Console.WriteLine(" Total Rows Retrieved: " + \r
- nRows);
- }
-
- // Used to read data from IDataReader after calling IDbCommand:ExecuteReader()
- public static void ReadData(IDataReader rdr) {
-
- int results = 0;
- if(rdr == null) {
-
- Console.WriteLine("IDataReader has a Null Reference.");
- }
- else {
- do {\r
- results++;\r
- if(rdr.FieldCount > 0) {\r
- // Results for\r
- // SQL SELECT Queries\r
- // have RecordsAffected = -1\r
- // and GetSchemaTable() returns a reference to a DataTable\r
- DataTable dt = rdr.GetSchemaTable();\r
- Console.WriteLine("Result is from a SELECT SQL Query. Records Affected: " + rdr.RecordsAffected);\r
- \r
- Console.WriteLine("Result Set " + results + "...");\r
-\r
- ReadResult(rdr, dt);\r
- }\r
- if(rdr.RecordsAffected >= 0) {\r
- // Results for \r
- // SQL INSERT, UPDATE, DELETE Commands \r
- // have RecordsAffected >= 0\r
- Console.WriteLine("Result is from a SQL Command (INSERT,UPDATE,DELETE). Records Affected: " + rdr.RecordsAffected);\r
- }\r
- else {\r
- // Results for\r
- // SQL Commands not INSERT, UPDATE, nor DELETE\r
- // have RecordsAffected == -1\r
- // and GetSchemaTable() returns a null reference\r
- Console.WriteLine("Result is from a SQL Command not (INSERT,UPDATE,DELETE). Records Affected: " + rdr.RecordsAffected);\r
- }\r
- } while(rdr.NextResult());\r
- Console.WriteLine("Total Result sets: " + results);\r
- \r
- rdr.Close();
- }
- }
-
- /* MySQL provider tests */
- public static void PerformTest (IDbConnection cnc) {
-
- IDataReader reader;
- Object oDataValue;
-
- Console.WriteLine ("\tMySQL provider specific tests...\n");
-
- /* Drops the mono_mysql_test table. */
-
- Console.WriteLine ("\t\tDrop table: ");
- try {
- DropTable (cnc);
- Console.WriteLine ("OK");
- }
- catch (MySqlException e) {
- Console.WriteLine("Error (don't worry about this one)" + e);
- }
-
- try {
- /* Creates a table with all supported data types */
- Console.WriteLine ("\t\tCreate table with all supported types: ");
- CreateTable (cnc);
- Console.WriteLine ("OK");
-
- /* Inserts values */
- Console.WriteLine ("\t\tInsert values for all known types: ");
- InsertData (cnc);
- Console.WriteLine ("OK");
-
- /* Update values */
- Console.WriteLine ("\t\tUpdate values: ");
- UpdateData (cnc);
- Console.WriteLine ("OK");
-
- /* Inserts values */
- Console.WriteLine ("\t\tInsert values for all known types: ");
- InsertData (cnc);
- Console.WriteLine ("OK");
-
- /* Select aggregates */
- SelectAggregate (cnc, "count(*)");
- SelectAggregate (cnc, "avg(int_value)");
- SelectAggregate (cnc, "min(char_value)");
- SelectAggregate (cnc, "max(integer_value)");
- SelectAggregate (cnc, "sum(double_value)");
-
- /* Select values */
- Console.WriteLine ("\t\tSelect values from the database: ");
- reader = SelectData (cnc);
- ReadData(reader);
-
- /* SQL Command via ExecuteReader/MySqlDataReader */
- /* Command is not INSERT, UPDATE, or DELETE */
- Console.WriteLine("\t\tCall ExecuteReader with a SQL Command. (Not INSERT,UPDATE,DELETE).");
- reader = SelectDataUsingCommand(cnc);
- ReadData(reader);
-
- /* SQL Command via ExecuteReader/MySqlDataReader */
- /* Command is INSERT, UPDATE, or DELETE */
- Console.WriteLine("\t\tCall ExecuteReader with a SQL Command. (Is INSERT,UPDATE,DELETE).");
- reader = SelectDataUsingInsertCommand(cnc);
- ReadData(reader);
-\r
- // Call a Stored Procedure named Version()\r
- Console.WriteLine("\t\tCalling stored procedure version()");\r
- object obj = CallStoredProcedure(cnc);\r
- Console.WriteLine("Result: " + obj);\r
-\r
- Console.WriteLine("Database Server Version: " + \r
- ((MySqlConnection)cnc).ServerVersion);\r
-\r
- /* Clean up */
- //Console.WriteLine ("Clean up...");
- //Console.WriteLine ("\t\tDrop table...");
- //DropTable (cnc);
- //Console.WriteLine("OK");
- }
- catch(Exception e) {
- Console.WriteLine("Exception caught: " + e);
- }
- }
-
- [STAThread]\r
- public static void Main(string[] args) {\r
-\r
- MySqlConnection dbconn = new MySqlConnection ();\r
- \r
- // ConnectionString can be:\r
- // "Server=localhost;Database=test;User ID=someuser;Password=somepass"\r
- // or it could be:\r
- // "host=localhost;dbname=test;user=someuser;passwd=somepass"\r
- string connectionString =
- "dbname=test;";\r
- dbconn.ConnectionString = connectionString;\r
-\r
- dbconn.Open();\r
- PerformTest(dbconn);
- dbconn.Close();
- }
- }
-}
+++ /dev/null
-
-namespace TestSystemDataSqlClient {
- using System;
- using System.Collections;
- using System.Data;
- using System.Data.Common;
- using Mono.Data.MySql;
-
- public class TestSqlDataAdapter {
- public static void Test() {
- string connectionString;
- string sqlQuery;
-
- MySqlDataAdapter adapter = null;
- DataSet dataSet = null;
-
- connectionString =
- "dbname=test;";
-
-
- sqlQuery = "select * from mono_mysql_test";
-
- System.Console.WriteLine ("new MySqlDataAdapter...");
- adapter = new MySqlDataAdapter (sqlQuery,
- connectionString);
-
- System.Console.WriteLine ("new DataSet...");
- dataSet = new DataSet ();
-
- System.Console.WriteLine("Fill...");
- adapter.Fill (dataSet, "Table1");
-
- System.Console.WriteLine ("Get Each Row in DataTable...");
- if (dataSet != null) {
-
- foreach (DataRow row in dataSet.Tables["Table1"].Rows)
- Console.WriteLine ("int_value: " +
- row["int_value"]);
-
- string filename = "DataSetTest.xml";
- Console.WriteLine ("Write DataSet to XML file: " +
- filename);
- dataSet.WriteXml (filename);
- }
- Console.WriteLine ("Done.");
-
- }
-
- public static void Main() {
- Test();
- }
- }
-}
+++ /dev/null
-//\r
-// Test/SqlDataRead.cs\r
-//\r
-// Test to do read a simple forward read only record set.\r
-// Using SqlCommand.ExecuteReader() to return a SqlDataReader\r
-// which can be used to Read a row\r
-// and Get a String or Int32.\r
-//\r
-// Author:\r
-// Daniel Morgan <danmorg@sc.rr.com>\r
-//\r
-// (C) 2002 Daniel Morgan\r
-//\r
-\r
-namespace TestSystemDataSqlClient {\r
- using System;\r
- using System.Data;\r
- using Mono.Data.MySql;\r
-\r
- class TestSqlDataReader {\r
-\r
- [STAThread]\r
- static void Main(string[] args) {\r
- Console.WriteLine("Started.");\r
-\r
- String connectionString = null;\r
- connectionString =
- "dbname=mysql";
- \r
- MySqlConnection con;\r
- Console.WriteLine("Create MySQL Connection...");\r
- con = new MySqlConnection(connectionString);\r
- Console.WriteLine("Open the connection...");\r
- con.Open();\r
-\r
- string sql;\r
- sql = "select * from db";\r
-\r
- Console.WriteLine("Create command...");\r
- MySqlCommand cmd;\r
- cmd = con.CreateCommand();\r
-\r
- cmd.CommandText = sql;\r
-\r
- MySqlDataReader reader;\r
- Console.WriteLine("ExecuteReader...");\r
- reader = cmd.ExecuteReader();\r
-\r
- int row = 0;\r
- Console.WriteLine("Reading data...");\r
- while(reader.Read()){\r
- row++;\r
- Console.WriteLine("Row: " + row);\r
- for(int col = 0; col < reader.FieldCount; col++) {\r
- Console.WriteLine(" Field: " + col);\r
- \r
- Console.WriteLine(" Name: " + \r
- reader.GetName(col));\r
- Console.WriteLine(" Value: " + \r
- reader.GetValue(col));\r
- }\r
- }\r
- Console.WriteLine("Clean up...");\r
-\r
- reader.Close();\r
- reader = null;\r
- cmd.Dispose();\r
- cmd = null;\r
- con.Close();\r
- con = null;\r
-\r
- Console.WriteLine("Done.");\r
- }\r
- }\r
-}\r
+++ /dev/null
-//
-// TestSqlExecuteScalar.cs
-//
-// To Test MySqlConnection and MySqlCommand by connecting
-// to a MySQL database
-// and then executing an SELECT SQL statement
-// using ExecuteScalar
-//
-// To use:
-// change strings to your database, userid, tables, etc...:
-// connectionString
-// selectStatement
-//
-// To test:
-// mcs TestMySqlExecuteScalar.cs -r System.Data.dll -r Mono.Data.MySql.dll
-// mono TestMySqlExecuteScalar.exe
-//
-// Author:
-// Daniel Morgan (danmorg@sc.rr.com)
-//
-// (C)Copyright 2002 Daniel Morgan
-//
-
-using System;
-using System.Data;
-using Mono.Data.MySql;
-
-namespace TestMonoDataMysql {
- class TestMySqlInsert {
- [STAThread]
- static void Main(string[] args) {
- MySqlConnection conn;
- MySqlCommand cmd;
-
- String connectionString;
- String selectStatement;
-
- connectionString =
- "dbname=test";
-
- selectStatement =
- "select count(*)" +
- "from sometable";
-
- // Connect to a MySQL database
- Console.WriteLine ("Connect to database...");
- conn = new MySqlConnection(connectionString);
- conn.Open();
-
- // create SELECT command
- Console.WriteLine ("Create Command initializing " +
- "with an SELECT statement...");
- cmd = new MySqlCommand (selectStatement, conn);
-
- // execute the SELECT SQL command
- Console.WriteLine ("Execute SELECT SQL Command...");
- Object obj = cmd.ExecuteScalar();
- Console.WriteLine ("Object: " + obj.ToString());
-
- // Close connection to database
- Console.WriteLine ("Close database connection...");
- conn.Close();
-
- Console.WriteLine ("Assuming everything " +
- "was successful.");
- }
- }
-}
+++ /dev/null
-//
-// TestSqlInsert.cs
-//
-// To Test MySqlConnection, MySqlCommand, and MySqlTransaction
-// by connecting to a MySQL database
-// and then executing some SQL statements
-//
-// To use:
-// change strings to your database, userid, tables, etc...:
-// connectionString
-// insertStatement
-// sqlToBeRolledBack
-//
-// To test:
-// mcs TestMySqlInsert.cs -r System.Data.dll -r Mono.Data.MySql.dll
-// mono TestMySqlInsert.exe
-//
-// Author:
-// Daniel Morgan (danmorg@sc.rr.com)
-//
-// (C)Copyright 2002 Daniel Morgan
-//
-
-using System;
-using System.Data;
-using Mono.Data.MySql;
-
-namespace TestMonoDataMysql
-{
- class TestMySqlInsert
- {
- [STAThread]
- static void Main(string[] args)
- {
- MySqlConnection conn;
- MySqlCommand cmd;
- MySqlTransaction trans;
-
- int rowsAffected;
-
- String connectionString;
- String insertStatement;
- String deleteStatement;
-
- connectionString =
- "dbname=test";
-
- insertStatement =
- "insert into sometable " +
- "(tid, tdesc) " +
- "values ('beer', 'Beer for All!') ";
-
- deleteStatement =
- "delete from sometable " +
- "where tid = 'beer' ";
-
- // Connect to a MySQL database
- Console.WriteLine ("Connect to database...");
- conn = new MySqlConnection(connectionString);
- conn.Open();
-
- // begin transaction
- Console.WriteLine ("Begin Transaction...");
- trans = conn.BeginTransaction();
-
- // create SQL DELETE command
- Console.WriteLine ("Create Command initializing " +
- "with an DELETE statement...");
- cmd = new MySqlCommand (deleteStatement, conn);
-
- // execute the DELETE SQL command
- Console.WriteLine ("Execute DELETE SQL Command...");
- rowsAffected = cmd.ExecuteNonQuery();
- Console.WriteLine ("Rows Affected: " + rowsAffected);
-
- // change the SQL command to an SQL INSERT Command
- Console.WriteLine ("Now use INSERT SQL Command...");
- cmd.CommandText = insertStatement;
-
- // execute the INSERT SQL command
- Console.WriteLine ("Execute INSERT SQL Command...");
- rowsAffected = cmd.ExecuteNonQuery();
- Console.WriteLine ("Rows Affected: " + rowsAffected);
-
- // if successfull at INSERT, commit the transaction,
- // otherwise, do a rollback the transaction using
- // trans.Rollback();
- // FIXME: need to have exceptions working in
- // Mono.Data.MySql classes before you can do rollback
- Console.WriteLine ("Commit transaction...");
- trans.Commit();
-
- cmd = null;
- trans = null;
-
- string sqlToBeRolledBack =
- "insert into sometable " +
- "(tid, tdesc) " +
- "values ('beer', 'Will not be committed!') ";
-
- Console.WriteLine("Create new command to be rolled back");
- cmd = conn.CreateCommand();
- cmd.CommandText = sqlToBeRolledBack;
-
- Console.WriteLine("Test Begin Transaction");
- trans = conn.BeginTransaction();
-
- Console.WriteLine("Execute INSERT SQL...");
- rowsAffected = cmd.ExecuteNonQuery();
- Console.WriteLine ("Rows Affected: " + rowsAffected);
-
- Console.WriteLine("Rollback Transaction...");
- trans.Rollback();
-
- // Close connection to database
- Console.WriteLine ("Close database connection...");
- conn.Close();
-
- Console.WriteLine ("Assuming everything " +
- "was successful.");
- Console.WriteLine ("Verify data in database to " +
- "see if row is there.");
- }
- }
-}
+++ /dev/null
-//\r
-// TestParameters.cs - test parameters for the MySQL .NET Data Provider in Mono\r
-// using *Parameter and *ParameterCollection\r
-//\r
-// Note: it currently only tests input parameters. Output is next on the list.\r
-// Then output/input and return parameters.\r
-//\r
-// Author: \r
-// Daniel Morgan <danmorg@sc.rr.com>\r
-//\r
-// (c)copyright 2002 Daniel Morgan\r
-//\r
-\r
-using System;\r
-using System.Collections;\r
-using System.Data;\r
-using Mono.Data.MySql;\r
-\r
-namespace TestMonoDataMySql {\r
-\r
- public class TestParameters {\r
- public static void Main() {\r
- Console.WriteLine("** Start Test...");\r
- \r
- String connectionString = null;\r
- connectionString =
- "dbname=test";
- \r
- MySqlConnection con;\r
- Console.WriteLine("** Creating connection...");\r
- con = new MySqlConnection(connectionString);\r
- Console.WriteLine("** opening connection...");\r
- con.Open();\r
- \r
- string charValue = "CD";\r
-\r
- string sql;\r
- sql = "SELECT char_value, int_value FROM mono_mysql_test WHERE char_value = :inCharValue";\r
- \r
- Console.WriteLine("** Creating command...");\r
- MySqlCommand cmd = new MySqlCommand(sql, con);\r
- \r
- // add parameter for inTableName\r
- Console.WriteLine("** Create parameter...");\r
- MySqlParameter parm = new MySqlParameter("inCharValue", DbType.String); \r
- \r
- Console.WriteLine("** set direction of parameter to input");\r
- parm.Direction = ParameterDirection.Input;\r
- \r
- Console.WriteLine("** set the parameter value...");\r
- parm.Value = charValue;\r
- \r
- Console.WriteLine("** add parameter to parameters collection in the command...");\r
- cmd.Parameters.Add(parm);\r
- \r
- MySqlDataReader rdr;\r
- Console.WriteLine("** ExecuteReader()...");\r
- \r
- rdr = cmd.ExecuteReader();\r
- \r
- Console.WriteLine("[][] And now we are going to our results [][]...");\r
- int c;\r
- int results = 0;\r
- do {\r
- results++;\r
- Console.WriteLine("Result Set " + results + "...");\r
-\r
- // get the DataTable that holds\r
- // the schema\r
- DataTable dt = rdr.GetSchemaTable();\r
- \r
- // number of columns in the table\r
- Console.WriteLine(" Total Columns: " +\r
- dt.Columns.Count);\r
-\r
- // display the schema\r
- foreach (DataRow schemaRow in dt.Rows) {\r
- foreach (DataColumn schemaCol in dt.Columns)\r
- Console.WriteLine(schemaCol.ColumnName + \r
- " = " + \r
- schemaRow[schemaCol]);\r
- Console.WriteLine();\r
- }\r
-\r
- string output, metadataValue, dataValue;\r
- int nRows = 0;\r
-\r
- // Read and display the rows\r
- while(rdr.Read()) {\r
- Console.WriteLine(" Row " + nRows + ": ");\r
-\r
- for(c = 0; c < rdr.FieldCount; c++) {\r
- // column meta data \r
- DataRow dr = dt.Rows[c];\r
- metadataValue = \r
- " Col " + \r
- c + ": " + \r
- dr["ColumnName"];\r
- \r
- // column data\r
- if(rdr.IsDBNull(c) == true)\r
- dataValue = " is NULL";\r
- else\r
- dataValue = \r
- ": " + \r
- rdr.GetValue(c);\r
- \r
- // display column meta data and data\r
- output = metadataValue + dataValue; \r
- Console.WriteLine(output);\r
- }\r
- nRows++;\r
- }\r
- Console.WriteLine(" Total Rows: " + \r
- nRows);\r
- } while(rdr.NextResult());\r
- Console.WriteLine("Total Result sets: " + results);\r
-\r
- con.Close();\r
- }\r
- }\r
-}\r