示例#1
0
 private static void mssql_trunc_table(Sqlcreds sc)
 {
     // Neue Datenbankverbindung
     SqlConnection sqlCon = new SqlConnection();
     // Connectionstring wird sqlConnection zugewiesen
     sqlCon.ConnectionString = sc.getMssqlConStr();
     // Verbindung zur Datenbank herstellen
     sqlCon.Open();
     // Querystring
     string strSqlQuery = "TRUNCATE TABLE "+sc.getTableName()+";";
     // SQLCommand
     SqlCommand sqlCmd = new SqlCommand(strSqlQuery, sqlCon);
     int intCheckQuery = sqlCmd.ExecuteNonQuery();
     Console.WriteLine("Tabelle geleert: "+ sc.getDatabase()+"."+sc.getTableName());
     sqlCon.Close();
 }
示例#2
0
        private static void walkFoldersSql(DirectoryInfo disql, Sqlcreds sc)
        {
            int lc = 0;
            string sqlcommand = "";

            Console.WriteLine("walkFoldersSql: Versuche Verbindung ...");

            try
            {

                // Alle Verzeichnisse rekursiv durchlaufen
                foreach (DirectoryInfo subdir in disql.GetDirectories())
                {
                    walkFoldersSql(subdir, sc);
                }

                // Alle Dateien des Verzeichnisses durchlaufen
                foreach (FileInfo fi in disql.GetFiles())
                {
                    ++gc;
                    ++lc;
                    MySqlConnection connection = new MySqlConnection(sc.getMysqlConStr());
                    MySqlCommand command = connection.CreateCommand();

                    String output = DateTime.Now + ": add Nr." + gc + " [" + hrs(fi.Length) + "/" + hrs(globalsize) + " ges]: " + fi.FullName;
                    Console.WriteLine(output);
                    FileAppend(logfilename, output + "\n");

                    connection.Open();
                    command.CommandText = "INSERT INTO `" + sc.getDatabase() + "`.`" + sc.getTableName()
                        + "` (`name`, `path`, `loc`, `size`, `csum`, `dom`, `owner`, `group`, `stime`, `atime`, `ctime`, `mtime`, `dups`) VALUES ('"
                        + fi.Name + "', '" + fi.FullName.Replace("\\", "\\\\") + "', '" + fi.FullName.Split('\\')[0] + "', '" + fi.Length + "', '"
                        + Datei2SHA(fi.FullName)/*"--not computed--"*/ + "', '" + File.GetAccessControl(@fi.FullName).GetOwner(typeof(NTAccount)).ToString().Split('\\')[0]
                        + "', '" + File.GetAccessControl(@fi.FullName).GetOwner(typeof(NTAccount)).ToString().Split('\\')[1] + "', '"
                        + File.GetAccessControl(@fi.FullName).GetGroup(typeof(NTAccount)).ToString().Split('\\')[1] + "', '" + UnixTime(DateTime.Now) + "', '" + UnixTime(fi.LastAccessTime) + "', '"
                        + UnixTime(fi.CreationTime) + "', '" + UnixTime(fi.LastWriteTime) + "', '1');";
                    MySqlDataReader Reader;
                    Reader = command.ExecuteReader();
                    globalsize += fi.Length;
                    connection.Close();

                }
                Console.WriteLine("walkFoldersSql: " + lc + " Zeilen hinzugefuegt.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
示例#3
0
        public static bool mysql_insert_row(Sqlcreds sc, String filepath)
        {
            bool erg = true;

            Console.WriteLine("mysql_insert_row: Versuche Verbindung zu: " + sc.getMysqlConStr());

            MySqlConnection connection = new MySqlConnection(sc.getMysqlConStr());
            MySqlCommand command = connection.CreateCommand();

            //Testdaten
            command.CommandText = "INSERT INTO `"+sc.getDatabase()+"`.`"
                +sc.getTableName()+"` (`name`, `path`, `loc`, `size`, `csum`, `owner`, `group`, `stime`, `atime`, `ctime`, `mtime`, `dups`) VALUES ('"
                + "" + "', '"+filepath+"', 'c:', '1234', 'mmmmfc92da241694750979ee6cf582f2d5d7d28e18335de05abc54d0560e0f5302860c652bf08d560252aa5e74210546f369fbbbce8c12cfc7957b2652fe9a75',"
                + " 'm', 'm', CURRENT_TIMESTAMP, '1983-10-10 22:11:02', '1983-01-01 00:11:02', '1983-10-10 22:11:11', '1');";
            MySqlDataReader Reader;
            connection.Open();
            Reader = command.ExecuteReader();
            while (Reader.Read())
            {
                string row = "";
                for (int i = 0; i < Reader.FieldCount; i++)
                    row += Reader.GetValue(i).ToString() + ", ";

                Console.WriteLine(row);
            }
            connection.Close();

            Console.WriteLine("Trenne Verbindung...");
            return erg;
        }