-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f00b0b2
commit c471c66
Showing
5 changed files
with
80 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
Team123it.Arcaea.MarveCube/System.Enhance (Part)/System.Enhance.MySql.Data.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using MySql.Data.MySqlClient; | ||
using System.Collections; | ||
using System.IO; | ||
using System.Text; | ||
|
||
namespace System.Enhance.MySql.Data | ||
{ | ||
public class MysqlExecutor | ||
{ | ||
public static bool ExecuteSqlFileData(string sqlConnString, string varData) | ||
{ | ||
var stream = new MemoryStream(); | ||
var ws = new StreamWriter(stream, Encoding.UTF8); | ||
ws.Write(varData); | ||
ws.Flush(); | ||
stream.Seek(0, SeekOrigin.Begin); | ||
var rs = new StreamReader(stream, Encoding.UTF8); | ||
var alSql = new ArrayList(); | ||
string commandText = ""; | ||
string varLine = ""; | ||
while (rs.Peek() > -1) | ||
{ | ||
varLine = rs.ReadLine(); | ||
if (varLine == "") | ||
{ | ||
continue; | ||
} | ||
if (varLine != "GO") | ||
{ | ||
commandText += varLine; | ||
commandText += "\r\n"; | ||
} | ||
else | ||
{ | ||
commandText += ""; | ||
} | ||
} | ||
alSql.Add(commandText); | ||
rs.Close(); | ||
try | ||
{ | ||
ExecuteCommand(sqlConnString, alSql); | ||
return true; | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw; | ||
} | ||
} | ||
private static void ExecuteCommand(string sqlConnString, ArrayList varSqlList) | ||
{ | ||
using var conn = new MySqlConnection(sqlConnString); | ||
conn.Open(); | ||
var cmd = conn.CreateCommand(); | ||
try | ||
{ | ||
foreach (string varcommandText in varSqlList) | ||
{ | ||
cmd.CommandText = varcommandText; | ||
cmd.ExecuteNonQuery(); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw; | ||
} | ||
finally | ||
{ | ||
conn.Close(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters