Skip to content

Commit

Permalink
399:MySql 处理存储过程Out值。(2016-10-19)
Browse files Browse the repository at this point in the history
400:MySql 批量方法解决了Bit类型和空表时自增ID被置为1的问题(2016-10-20)
401:JsonHelper、NoSqlAction小优化调整(2016-10-20)
  • Loading branch information
cyq1162 committed Oct 19, 2016
1 parent 7b983be commit f847517
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 35 deletions.
19 changes: 11 additions & 8 deletions Action/NoSqlAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ private MDataTable Table
else if (_tableList.ContainsKey(_FileFullName))
{
return _tableList[_FileFullName];
//if (_Table.Rows.Count == 0)
//{
// _tableList.Remove(_FileFullName);// 会引发最后一条数据无法删除的问题。
//}
//else
//{
// return _Table;
//}
if (_Table.Rows.Count == 0)
{
_tableList.Remove(_FileFullName);// 会引发最后一条数据无法删除的问题(已修正该问题,所以可开放)
}
else
{
return _Table;
}
}

switch (_DalType)
Expand Down Expand Up @@ -279,6 +279,7 @@ internal bool Delete(object where, out int count)
count = rowList.Count;
if (count > 0)
{
bool isDeleteAll = count == Table.Rows.Count;
for (int i = rowList.Count - 1; i >= 0; i--)
{
try
Expand All @@ -299,7 +300,9 @@ internal bool Delete(object where, out int count)
}
catch { }
}
if (isDeleteAll) { Save(); }
needToSaveState = 2;

return true;
}
}
Expand Down
4 changes: 4 additions & 0 deletions DAL/DalEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public enum ParaType
/// </summary>
OutPut,
/// <summary>
/// 输入输出类型
/// </summary>
InputOutput,
/// <summary>
/// 返回值类型
/// </summary>
ReturnValue,
Expand Down
17 changes: 17 additions & 0 deletions DAL/DbBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,19 @@ public virtual bool AddParameters(string parameterName, object value, DbType dbT
}
internal virtual void AddCustomePara(string paraName, ParaType paraType, object value, string typeName)
{
switch (paraType)
{

case ParaType.OutPut:
AddParameters(paraName, null, DbType.String, 2000, ParameterDirection.Output);
break;
case ParaType.InputOutput:
AddParameters(paraName, null, DbType.String, 2000, ParameterDirection.InputOutput);
break;
case ParaType.ReturnValue:
AddParameters(paraName, null, DbType.Int32, 32, ParameterDirection.ReturnValue);
break;
}
}
//internal virtual void AddCustomePara(string paraName, ParaType paraType, object value)
//{
Expand Down Expand Up @@ -668,6 +681,10 @@ private void SetCommandText(string commandText, bool isProc)
{
_com.CommandText += " COLLATE NOCASE";//忽略大小写
}
//else if (isProc && dalType == DalType.MySql)
//{
// _com.CommandText = "Call " + _com.CommandText;
//}
_com.CommandType = isProc ? CommandType.StoredProcedure : CommandType.Text;
if (isProc)
{
Expand Down
6 changes: 3 additions & 3 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[assembly: AssemblyTitle("CYQ.Data 数据层(ORM)框架 V5 版本")]
[assembly: AssemblyDescription("论坛:http://www.cyqdata.com/cyqdata")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("秋式软件 (2016-10-19)")]
[assembly: AssemblyCompany("秋式软件 (2016-10-20)")]
[assembly: AssemblyProduct("CYQ.Data 数据层(ORM)框架 V5 版本")]
[assembly: AssemblyCopyright("版权所有 (C) 秋式软件 2010-2020")]
[assembly: AssemblyTrademark("CYQ.Data")]
Expand All @@ -31,5 +31,5 @@
//
// 可以指定所有这些值,也可以使用“修订号”和“内部版本号”的默认值,
// 方法是按如下所示使用“*”:
[assembly: AssemblyVersion("5.6.7.0")]
[assembly: AssemblyFileVersion("5.6.7.0")]
[assembly: AssemblyVersion("5.6.7.1")]
[assembly: AssemblyFileVersion("5.6.7.1")]
2 changes: 1 addition & 1 deletion SQL/SqlCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ internal static string GetWhereIn(MCellStruct ms, List<string> items, DalType da

internal static string MySqlBulkCopySql = "LOAD DATA LOCAL INFILE '{0}' INTO TABLE {1} CHARACTER SET utf8 FIELDS TERMINATED BY '{2}' LINES TERMINATED BY '\r\n' {3}";
internal static string OracleBulkCopySql = "LOAD DATA INFILE '{0}' APPEND INTO TABLE {1} FIELDS TERMINATED BY '{2}' OPTIONALLY ENCLOSED BY '\"' {3}";
internal static string OracleSqlIDR = " userid={0} control='{1}' log='{2}'";//sqlldr
internal static string OracleSqlIDR = " userid={0} control='{1}'";//sqlldr
/// <summary>
/// 获得批量导入的列名。
/// </summary>
Expand Down
48 changes: 26 additions & 22 deletions Table/MDataTableBatchAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,7 @@ internal bool Insert(bool keepID)
}
else if (dalTypeTo == DalType.MySql && IsAllowBulkCopy(DalType.MySql))
{
// Mysql在表为空时,用Load Data命令第一行的ID会被设置为起始索引1,所以自增加又带ID的,先不走Load Data
if (!keepID || !mdt.Columns.FirstPrimary.IsAutoIncrement)
{
return LoadDataInsert(dalTypeTo, keepID);
}
return LoadDataInsert(dalTypeTo, keepID);
}

//if (dalTypeTo == DalType.Txt || dalTypeTo == DalType.Xml)
Expand Down Expand Up @@ -517,12 +513,6 @@ bool IsAllowBulkCopy(DalType dalType)
{
case 999:
return false;
case 3://bool型也会有问题
if (dalType == DalType.MySql)
{
return false;
}
break;
}
}
try
Expand Down Expand Up @@ -560,7 +550,7 @@ internal bool LoadDataInsert(DalType dalType, bool keepID)
if (dalType == DalType.Oracle)
{
string ctlPath = CreateCTL(sql, path);
sql = string.Format(SqlCreate.OracleSqlIDR, "sa/123456@ORCL", ctlPath, ctlPath.Replace(".ctl", ".out"));//只能用进程处理
sql = string.Format(SqlCreate.OracleSqlIDR, "sa/123456@ORCL", ctlPath);//只能用进程处理
}
try
{
Expand Down Expand Up @@ -593,25 +583,21 @@ internal bool LoadDataInsert(DalType dalType, bool keepID)
_dalHelper.Dispose();
_dalHelper = null;
}
// File.Delete(path);
IOHelper.Delete(path);//删除文件。
}
return false;
}
private static string CreateCTL(string sql, string path)
{
path = path.Replace(".txt", ".ctl");
path = path.Replace(".csv", ".ctl");
IOHelper.Write(path, sql);
return path;
}
private static string MDataTableToFile(MDataTable dt, bool keepID, DalType dalType)
{
string path = Path.GetTempPath() + dt.TableName + ".txt";
string path = Path.GetTempPath() + dt.TableName + ".csv";//不能用.txt(会产生默认编码,影响第一行数据(空表时自增的ID被置为初始1)
using (StreamWriter sw = new StreamWriter(path, false, Encoding.UTF8))
{
if (dalType == DalType.Oracle)
{
sw.WriteLine();//先输出空行(Oracle需要空行在前)
}
MCellStruct ms;
string value;
foreach (MDataRow row in dt.Rows)
Expand All @@ -623,14 +609,32 @@ private static string MDataTableToFile(MDataTable dt, bool keepID, DalType dalTy
{
continue;
}
else if (dalType == DalType.MySql && row[i].IsNull)
{
sw.Write("\\N");//Mysql用\N表示null值。
}
else
{
value = row[i].ToString();
if (ms.SqlType == SqlDbType.Bit && value != "1")
if (ms.SqlType == SqlDbType.Bit)
{
int v = (value.ToLower() == "true" || value == "1") ? 1 : 0;
if (dalType == DalType.MySql)
{
byte[] b = new byte[1];
b[0] = (byte)v;
value = System.Text.Encoding.UTF8.GetString(b);//mysql必须用字节存档。
}
else
{
value = v.ToString();
}

}
else
{
value = (value.ToLower() == "true") ? "1" : "0";
value = value.Replace("\\", "\\\\");//处理转义符号
}
value = value.Replace("\\", "\\\\");//处理转义符号
sw.Write(value);
}

Expand Down
5 changes: 4 additions & 1 deletion 更新记录.txt
Original file line number Diff line number Diff line change
Expand Up @@ -611,4 +611,7 @@
395��JsonHelper ���������������ͻ�ԭ��2016-10-17)
396��JsonHelper ����JsonǶ�����⡣��2016-10-18)
397��MDataTable �Ż������������⡣��2016-10-18)
398��MDataRow��MDataColumn ��ToTable() ������Ӧ(����������ʾ)��2016-10-19)
398��MDataRow��MDataColumn ��ToTable() ������Ӧ(����������ʾ)��2016-10-19)
399��MySql �����洢����Outֵ����2016-10-19��
400��MySql �������������Bit���ͺͿձ�ʱ����ID����Ϊ1�����⣨2016-10-20��
401��JsonHelper��NoSqlActionС�Ż�������2016-10-20��

0 comments on commit f847517

Please sign in to comment.