Esempio n. 1
0
        public void CreateTable(string tableName, List <SQLColumn> fields)
        {
            LoggerZ.Log(string.Format("Creating {0}", tableName), Level.Debug, LogTarget.Console, LogTarget.File);
            string createString = string.Format("IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='{0}' AND xtype='U') CREATE TABLE {0} (", tableName);

            foreach (SQLColumn field in fields)
            {
                createString += string.Format("[{0}] varchar({1}) NULL,", field.Name, (field.Length > 8000 ? "MAX" : field.Length.ToString()));
            }
            RunQuery(createString.TrimEnd(',') + ");");
            LoggerZ.Log(string.Format("Created {0}", tableName), Level.Debug, LogTarget.Console, LogTarget.File);
        }
Esempio n. 2
0
 public void Connect()
 {
     try
     {
         connection = new OdbcConnection(GenerateODBCConnectionString());
         connection.Open();
         LoggerZ.Log(String.Format("Connection opened: {0}", connection.ConnectionString), Level.Debug, LogTarget.Console, LogTarget.File);
     }
     catch (Exception e)
     {
         LoggerZ.Log(String.Format("could not open ODBC connection with paramenters:{0}\n{1}", GenerateODBCConnectionString(), e), Level.Fatal, LogTarget.Console, LogTarget.File);
         Console.ReadLine();
         Environment.Exit(160);
     }
 }
Esempio n. 3
0
        private string GenerateODBCConnectionString()
        {
            string connectionString;

            if (DSN != "")
            {
                connectionString = "DSN=" + DSN + ";";
                if (Database != "")
                {
                    connectionString += "database=" + Database + ";";
                }
            }
            else if (Driver != "" & Server != "" & Uid != "" & Database != "")
            {
                connectionString = "driver=" + Driver + ";server=" + Server + ";uid=" + Uid + ";pwd=" + Pwd + ";database=" + Database + ";";
            }
            else
            {
                LoggerZ.FatalError("All Connection Data was not set!");
                return("");
            }
            return(connectionString);
        }
Esempio n. 4
0
        public void BulkInsert(string tableName, DataTable data)
        {
            string columns = "";

            foreach (DataColumn column in data.Columns)
            {
                columns += "[" + column.ColumnName + "],";
            }
            string insertString = string.Format("INSERT INTO {0}({1}) Values ", tableName, columns.TrimEnd(','));
            int    rowCounter   = 0;
            string rowString    = "";

            foreach (DataRow row in data.Rows)
            {
                rowString += "(";
                foreach (object item in row.ItemArray)
                {
                    rowString += "'" + item.ToString().Trim(' ').Replace("'", "''") + "',";
                }
                rowString = rowString.TrimEnd(',') + "),";
                rowCounter++;
                if (rowCounter % SQLZ.bulkInsertCount == 0)
                {
                    RunQuery(string.Format("{0}{1}", insertString, rowString.TrimEnd(',')));
                    rowString = "";
                    LoggerZ.Log(string.Format("Inserted {0} rows into {1}", rowCounter, tableName), Level.Debug, LogTarget.Console);
                }
            }
            if (rowCounter % SQLZ.bulkInsertCount != 0)
            {
                RunQuery(string.Format("{0}{1}", insertString, rowString.TrimEnd(',')));
                rowString = "";
                LoggerZ.Log(string.Format("Inserted {0} rows into {1}", rowCounter, tableName), Level.Debug, LogTarget.Console);
            }
            LoggerZ.Log(string.Format("{1} extracted, {0} rows inserted", rowCounter, tableName), Level.Debug, LogTarget.Console, LogTarget.File);
        }
Esempio n. 5
0
        private static void GetSettingsFromXML(string filepath)
        {
            try
            {
                XElement settingsXml             = XElement.Parse(String.Join("\n", File.ReadAllLines(filepath)));
                IEnumerable <XElement> settingsX = settingsXml.Elements();
                foreach (XElement setting in settingsX)
                {
                    switch (setting.Name.ToString())
                    {
                        #region Logger Settings
                    case "Logger":
                        foreach (XElement element in setting.Elements())
                        {
                            if (element.Name == "LogFilePath")
                            {
                            }
                            else
                            {
                                foreach (XElement level in element.Elements())
                                {
                                    loggerSettings.Add(element.Name.ToString() + "." + level.Name.ToString(), (level.Value == "true"));
                                }
                            }
                        }
                        break;
                        #endregion

                        #region SQL Settings
                    case "SQL":
                        foreach (XElement element in setting.Elements())
                        {
                            if (element.Name == "BulkInsertCount")
                            {
                                //bulkInsertCount = Int32.Parse(element.Value.ToString());
                            }
                        }

                        break;
                        #endregion

                        #region ODBC Settings
                    case "ODBC":
                        OdbcZ.defaultConnection = new ODBCHandler(setting.Elements());
                        break;
                        #endregion

                        #region Discord Settings
                    case "Discord":
                        break;
                        #endregion
                    }


                    if (setting.Name == "Connection")
                    {
                    }
                    else if (setting.Name == "Logging")
                    {
                    }
                    else if (setting.Name == "General")
                    {
                        foreach (XElement element in setting.Elements())
                        {
                        }
                    }
                    else if (setting.Name == "Discord")
                    {
                    }
                }
            }
            catch (Exception e)
            {
                LoggerZ.FatalError(String.Format("Error: could not read lines in file \"{0}\"\n{1}", filepath, e.Message));
            }
        }