1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.SQLite;
using System.Data.Common;
using static QuantiqueTime.Collapseoftime;//affichage personnaliser, même fonction de base
namespace NSqlISharp
{
public class SqlInsert
{
//constructeur
class SqlDataInsert { }
public void T_FileNormal(ref List<string> l_fullpath, ref List<long> l_sizefile, string pdb)
{
string sql = "INSERT INTO T_FichierNormal(fullpath,sizefile,sha256)" +
"values(@fullpath,@sizefile,@sha256)";
SQLiteParameter[] parameters = new SQLiteParameter[]{
new SQLiteParameter("@fullpath"),
new SQLiteParameter("@sizefile"),
new SQLiteParameter("@sha256") };
SqlInsert sqlI = new SqlInsert();
QuantiqueTime.Collapseoftime T = new QuantiqueTime.Collapseoftime();
T.TimeExcute(true);
sqlI.ExecuteNonQuery(sql, parameters, pdb, ref l_fullpath, ref l_sizefile);
T.TimeExcute(false);
}
private int ExecuteNonQuery(string sql, SQLiteParameter[] parameters, string pdb, ref List<string> l_fullpath, ref List<long> l_sizefile)
{
int affectedRows = 0;
string Buffersha256 = "";
Allfile.CFileSystem MeFile;
MeFile = new Allfile.CFileSystem();
try
{
using (SQLiteConnection connection = new SQLiteConnection(pdb))
{
connection.Open();
using (DbTransaction transaction = connection.BeginTransaction())
{
using (SQLiteCommand command = new SQLiteCommand(connection))
{
command.CommandText = sql;
//boucler sur les liste ?
for (int i = 0; i < l_fullpath.Count(); i++)
{
Buffersha256 = MeFile.Ssha256sum(l_fullpath[i]);
if (Buffersha256 != "0")
{
parameters[0].Value = l_fullpath[i];
parameters[1].Value = l_sizefile[i];
parameters[2].Value = Buffersha256;
command.Parameters.AddRange(parameters);
affectedRows = command.ExecuteNonQuery();
}
else
{
Console.WriteLine("Erreur: " + l_fullpath[i] + " : " + Buffersha256); ;
}
}
}
transaction.Commit();
}
connection.Close();
}
}
catch (SQLiteException sqle)
{
Sql_Printerror(ref pdb, ref sqle);
}
return affectedRows;
}
private void Sql_Printerror(ref string pdb, ref SQLiteException sqle)
{
Console.WriteLine("************************************************");
Console.WriteLine("Erreur sur la base de donnée (insert) fichier Sqlinsert.cs");
Console.WriteLine(pdb);
Console.WriteLine(sqle);
Console.WriteLine("************************************************");
Sleep(20);
}
}
} |
Partager