MySQL是免費的數據庫
而實際上
通過閱讀源代碼
具體如何進行呢?
打開工程後
以下是引用片段
#region LICENSE
/*
MySQLDriverCS: An C# driver for MySQL
Copyright (c)
This file is part of MySQLDriverCS
MySQLDriverCS 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
(at your option) any later version
MySQLDriverCS 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
GNU General Public License for more details
You should have received a copy of the GNU General Public License
along with MySQLDriverCS; if not
Foundation
*/
#endregion
using System;
using System
using System
namespace MySQLDriverCS
{
//[StructLayout(LayoutKind
public class MYSQL_FIELD_FACTORY
{
static string version;
public static IMYSQL_FIELD GetInstance()
{
if (version==null)
{
version = CPrototypes
}
if (version
{
return new MYSQL_FIELD_VERSION_
}
else
return new MYSQL_FIELD_VERSION_
}
}
public interface IMYSQL_FIELD
{
string Name{get;}
uint Type{get;}
long Max_Length {get;}
}
///<summary>
/// Field descriptor
///</summary>
[StructLayout(LayoutKind
internal class MYSQL_FIELD_VERSION_
{
///<summary>
/// Name of column
///</summary>
public string name;
///<summary>
/// Table of column if column was a field
///</summary>
public string table;
//public string org_table; /* Org table name if table was an alias */
//public string db; /* Database for table */
///<summary>
/// def
///</summary>
public string def;
///<summary>
/// length
///</summary>
public long length;
///<summary>
/// max_length
///</summary>
public long max_length;
///<summary>
/// Div flags
///</summary>
public uint flags;
///<summary>
/// Number of decimals in field
///</summary>
public uint decimals;
///<summary>
/// Type of field
///</summary>
public uint type;
///<summary>
/// Name
///</summary>
public string Name
{
get{return name;}
}
///<summary>
/// Type
///</summary>
public uint Type
{
get{return type;}
}
///<summary>
/// Max_Length
///</summary>
public long Max_Length
{
get {return max_length;}
}
}
///<summary>
/// Field descriptor
///</summary>
[StructLayout(LayoutKind
internal class MYSQL_FIELD_VERSION_
{
///<summary>
/// Name of column
///</summary>
public string name;
///<summary>
/// Original column name
///</summary>
public string org_name;
///<summary>
/// Table of column if column was a field
///</summary>
public string table;
///<summary>
/// Org table name if table was an alias
///</summary>
public string org_table;
///<summary>
/// Database for table
///</summary>
public string db;
///<summary>
/// Catalog for table
///</summary>
//public string catalog;
///<summary>
/// def
///</summary>
public string def;
///<summary>
/// length
///</summary>
public long length;
///<summary>
/// max_length
///</summary>
public long max_length;
///<summary>
/// name_length
///</summary>
//public uint name_length;
///<summary>
/// org_name_length
///</summary>
public uint org_name_length;
///<summary>
/// table_length
///</summary>
public uint table_length;
///<summary>
/// org_table_length
///</summary>
public uint org_table_length;
///<summary>
/// db_length
///</summary>
public uint db_length;
///<summary>
/// catalog_length
///</summary>
public uint catalog_length;
///<summary>
/// def_length
///</summary>
public uint def_length;
///<summary>
/// Div flags
///</summary>
public uint flags;
///<summary>
/// Number of decimals in field
///</summary>
public uint decimals;
///<summary>
/// Character set
///</summary>
public uint charsetnr;
///<summary>
/// Type of field
///</summary>
public uint type;
///<summary>
/// Name
///</summary>
public string Name
{
get {return name;}
}
///<summary>
/// Type
///</summary>
public uint Type
{
get {return type;}
}
///<summary>
/// Max_Length
///</summary>
public long Max_Length
{
get {return max_length;}
}
}
//[StructLayout(LayoutKind
public enum enum_field_types
{
FIELD_TYPE_DECIMAL
FIELD_TYPE_SHORT
FIELD_TYPE_FLOAT
FIELD_TYPE_NULL
FIELD_TYPE_LONGLONG
FIELD_TYPE_DATE
FIELD_TYPE_DATETIME
FIELD_TYPE_NEWDATE
FIELD_TYPE_ENUM=
FIELD_TYPE_SET=
FIELD_TYPE_TINY_BLOB=
FIELD_TYPE_MEDIUM_BLOB=
FIELD_TYPE_LONG_BLOB=
FIELD_TYPE_BLOB=
FIELD_TYPE_VAR_STRING=
FIELD_TYPE_STRING=
FIELD_TYPE_GEOMETRY=
};
///<summary>
/// C prototypes warpper for mysqllib
///</summary>
internal class CPrototypes
{
[ DllImport(
unsafe public static extern void* mysql_init(void* must_be_null);
[ DllImport(
unsafe public static extern void mysql_close(void* handle);
// BEGIN ADDITION
// Enables us to call mysql_option to activate compression and timeout
[ DllImport(
unsafe public static extern void mysql_options(void* mysql
// END ADDITION
[ DllImport(
unsafe public static extern void* mysql_real_connect(void* mysql
[ DllImport(
unsafe public static extern int mysql_query(void*mysql
[ DllImport(
unsafe public static extern void *mysql_store_result(void *mysql);
[ DllImport(
unsafe public static extern void mysql_free_result(void*result);
[ DllImport(
unsafe public static extern uint mysql_errno(void*mysql);
[ DllImport(
unsafe public static extern string mysql_error(void*mysql);
[ DllImport(
unsafe public static extern uint mysql_field_count(void*mysql);
[ DllImport(
unsafe public static extern ulong mysql_affected_rows(void*mysql);
[ DllImport(
unsafe public static extern uint mysql_num_fields(void*result);
[ DllImport(
unsafe public static extern ulong mysql_num_rows(void *result);
[ DllImport(
unsafe public static extern IntPtr mysql_fetch_field_direct(void*result
///<returns>Returns a string that represents the client library version</returns>
[DllImport(
EntryPoint=
public static extern string GetClientInfo();
[ DllImport(
unsafe public static extern IntPtr mysql_fetch_row(void*result);
[ DllImport(
unsafe public static extern int mysql_select_db(void*mysql
[ DllImport(
unsafe public static extern UInt
}
}
基本上是將C風格的基礎數據結構進的重新定義
具體如何利用這個庫進行操作
From:http://tw.wingwit.com/Article/program/net/201311/11566.html