init lserp cs 5.0
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Zhaizj.Framework.ORM;
|
||||
|
||||
namespace Zhaizj.Framework.Data {
|
||||
|
||||
|
||||
internal class MysqlDatabaseChecker : IDatabaseChecker {
|
||||
|
||||
private static readonly ILog logger = LogManager.GetLogger( typeof( MysqlDatabaseChecker ) );
|
||||
|
||||
private List<String> existTables = new List<String>();
|
||||
|
||||
private String _connectionString;
|
||||
|
||||
public String ConnectionString {
|
||||
get { return _connectionString; }
|
||||
set { _connectionString = value; }
|
||||
}
|
||||
|
||||
public DatabaseType DatabaseType {
|
||||
get { return DatabaseType.MySql; }
|
||||
set { }
|
||||
}
|
||||
|
||||
public void CheckDatabase() {
|
||||
|
||||
if (strUtil.IsNullOrEmpty( this._connectionString )) {
|
||||
throw new Exception( "connection string can not be empty" );
|
||||
}
|
||||
IDatabaseDialect dialect = DataFactory.GetDialect( DatabaseType.MySql );
|
||||
if (strUtil.IsNullOrEmpty( dialect.GetConnectionItem( this._connectionString, ConnectionItemType.Server ) )) {
|
||||
throw new Exception( "[mysql] server address is empty" );
|
||||
}
|
||||
if (strUtil.IsNullOrEmpty( dialect.GetConnectionItem( _connectionString, ConnectionItemType.Database ) )) {
|
||||
throw new Exception( "[mysql] database is empty" );
|
||||
}
|
||||
}
|
||||
|
||||
public void CheckTable( MappingClass mapping, String db ) {
|
||||
|
||||
logger.Info( "[mysql] begin check table" );
|
||||
IDbConnection connection = DataFactory.GetConnection( _connectionString, this.DatabaseType );
|
||||
connection.Open();
|
||||
|
||||
IDbCommand cmd = connection.CreateCommand();
|
||||
cmd.CommandText = "show tables";
|
||||
|
||||
IDataReader reader = cmd.ExecuteReader();
|
||||
|
||||
while (reader.Read()) {
|
||||
existTables.Add( reader[0].ToString() );
|
||||
logger.Info( "table found£º" + reader[0].ToString() );
|
||||
}
|
||||
|
||||
reader.Close();
|
||||
existTables = new MySqlTableBuilder().CheckMappingTableIsExist( cmd, db, existTables, mapping );
|
||||
|
||||
connection.Close();
|
||||
}
|
||||
|
||||
|
||||
public List<String> GetTables() {
|
||||
return existTables;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user