示例#1
0
        static void Init()
        {
            Console.WriteLine("VER 14 no sync commit - session");

            var pgConn = ReqProcessor.GetConnectionString();

            while (true)
            {
                Thread.Sleep(1000);
                try
                {
                    var host = Regex.Match(pgConn, "host=([^;]*)(;|$)", RegexOptions.IgnoreCase).Groups[1].Value;
                    var port = Regex.Match(pgConn, "port=([^;]*)(;|$)", RegexOptions.IgnoreCase).Groups[1].Value;
                    Console.WriteLine($"reaching {host}:{port}...");
                    var c = new TcpClient();
                    c.Connect(host, int.Parse(port));
                    if (c.Connected)
                    {
                        c.Close();
                        Console.WriteLine("POSTGRESQL IS REACHABLE");
                        break;
                    }
                    else
                    {
                        Console.WriteLine("NO POSTGRESQL FOUND");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("PG RELATED ERROR:");
                    Console.WriteLine(ex.Message);
                }
            }

            try
            {
                using var con = new NpgsqlConnection(pgConn);
                con.Open();
                TableSQL.Split(";").ToList().ForEach(sql =>
                {
                    if (string.IsNullOrWhiteSpace(sql))
                    {
                        return;
                    }
                    using var cmd   = con.CreateCommand();
                    cmd.CommandText = sql;
                    cmd.ExecuteNonQuery();
                });

                con.Close();
                Console.WriteLine("NPGSQL CONNECTED");
            }
            catch (Exception ex)
            {
                Console.WriteLine("NPGSQL RELATED ERROR:");
                Console.WriteLine(ex.Message);
            }
        }
示例#2
0
 public void TryReadDB(string sqlQuery)
 {
     IDbCommand dbCommand = dbConnection.CreateCommand();
     dbCommand.CommandText = sqlQuery;
     IDataReader reader = dbCommand.ExecuteReader();
     reader.Read();
     if(DataContainer.currData == null) DataContainer.currData = new List<TableSQL>();
     for(int i=0; i<reader.FieldCount;i++){
         TableSQL tempTable = new TableSQL();
         tempTable.name = reader.GetName(i);
         tempTable.datas = new List<string>();
         while(reader.Read()){
             tempTable.datas.Add(reader[i].ToString());
             //Debug.Log(reader[i].ToString());
         }
         DataContainer.currData.Add(tempTable);
         //Debug.Log(DataContainer.currData[i].name);
     }
     reader.Close();
     reader = null;
     dbCommand.Dispose();
     dbCommand = null;
 }
示例#3
0
 public void ReadDBColumn(string dBase)
 {
     List<string> tableNames = new List<string>();
     OpenSqlConnection();
     IDbCommand dbCommand = dbConnection.CreateCommand();
     dbCommand.CommandText = "SELECT TABLE_NAME FROM "+dBase+".INFORMATION_SCHEMA.TABLES";
     IDataReader reader = dbCommand.ExecuteReader();
     reader.Read();
     if(DataContainer.testTable == null) DataContainer.testTable = new List<RelationshipTable>();
     DataTable tempSQLTable = reader.GetSchemaTable();
     for(int i=0; i<reader.FieldCount;i++){
         tableNames.Add(reader.GetName(i));
         Debug.Log("name: "+reader.GetName(i));
         Debug.Log("byte: "+reader.GetByte(i));
         Debug.Log("char: "+reader.GetChar(i));
         Debug.Log("datatypename: "+reader.GetDataTypeName(i));
         Debug.Log("datetime: "+reader.GetDateTime(i));
         Debug.Log("fieldtype: "+reader.GetFieldType(i));
         Debug.Log("string: "+reader.GetString(i));
         Debug.Log("type: "+reader.GetType());
         Debug.Log("val: "+reader.GetValue(i));
         Debug.Log("schemanamespace: "+tempSQLTable.Namespace);
         Debug.Log("schematablename: "+tempSQLTable.TableName);
         Debug.Log("schemacolumname: "+tempSQLTable.Columns[i].ColumnName);
         Debug.Log("schemaconstraintname: "+tempSQLTable.Constraints[i].ConstraintName);
         Debug.Log("schemacontainer: "+tempSQLTable.Container.ToString());
         Debug.Log("schemadataset: "+tempSQLTable.DataSet.DataSetName);
         Debug.Log("schemarows: "+tempSQLTable.Rows[0].ItemArray[0].ToString());
     }
     reader.Close();
     reader = null;
     dbCommand.Dispose();
     dbCommand = null;
     for(int i=0; i< tableNames.Count; i++){
         RelationshipTable tempTable = new RelationshipTable();
         tempTable.column = new List<TableSQL>();
         tempTable.name = tableNames[i];
         dbCommand = dbConnection.CreateCommand();
         dbCommand.CommandText = "SELECT * FROM "+tableNames[i];
         reader = dbCommand.ExecuteReader();
         reader.Read();
         tempSQLTable = reader.GetSchemaTable();
         for(int j=0; j<reader.FieldCount;j++){
             TableSQL tempColumn = new TableSQL();
             tempColumn.name = reader.GetName(j);
             tempTable.column.Add(tempColumn);
             Debug.Log(DataContainer.currData[i].name);
             Debug.Log("name: "+reader.GetName(i));
             Debug.Log("byte: "+reader.GetByte(i));
             Debug.Log("char: "+reader.GetChar(i));
             Debug.Log("datatypename: "+reader.GetDataTypeName(i));
             Debug.Log("datetime: "+reader.GetDateTime(i));
             Debug.Log("fieldtype: "+reader.GetFieldType(i));
             Debug.Log("string: "+reader.GetString(i));
             Debug.Log("type: "+reader.GetType());
             Debug.Log("val: "+reader.GetValue(i));
             Debug.Log("schemanamespace: "+tempSQLTable.Namespace);
             Debug.Log("schematablename: "+tempSQLTable.TableName);
             Debug.Log("schemacolumname: "+tempSQLTable.Columns[i].ColumnName);
             Debug.Log("schemaconstraintname: "+tempSQLTable.Constraints[i].ConstraintName);
             Debug.Log("schemacontainer: "+tempSQLTable.Container.ToString());
             Debug.Log("schemadataset: "+tempSQLTable.DataSet.DataSetName);
             Debug.Log("schemarows: "+tempSQLTable.Rows[0].ItemArray[0].ToString());
         }
         reader.Close();
         reader = null;
         dbCommand.Dispose();
         dbCommand = null;
         DataContainer.testTable.Add(tempTable);
         CloseSqlConnection();
     }
     Data.AllocateData();
 }