2021-05-18 16:19:28 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using Npgsql;
|
|
|
|
|
|
2021-05-26 08:16:29 +00:00
|
|
|
|
namespace FarmmapsBulkSatDownload.Models
|
2021-05-18 16:19:28 +00:00
|
|
|
|
{
|
|
|
|
|
public class DB
|
|
|
|
|
{
|
|
|
|
|
public string Database;
|
|
|
|
|
public string User;
|
|
|
|
|
public string Password;
|
|
|
|
|
public string Host;
|
|
|
|
|
|
|
|
|
|
public string GetConnectionString()
|
|
|
|
|
{
|
|
|
|
|
NpgsqlConnectionStringBuilder sb = new NpgsqlConnectionStringBuilder();
|
|
|
|
|
sb.Database = Database;
|
|
|
|
|
sb.Host = Host;
|
|
|
|
|
sb.Username = User;
|
|
|
|
|
sb.Password = Password;
|
|
|
|
|
sb.Port = 5432;
|
|
|
|
|
|
|
|
|
|
return sb.ConnectionString;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int ExecuteNonQuery(string sql)
|
|
|
|
|
{
|
|
|
|
|
using (NpgsqlConnection conn = new NpgsqlConnection(GetConnectionString()))
|
|
|
|
|
{
|
|
|
|
|
conn.Open();
|
|
|
|
|
NpgsqlCommand command = conn.CreateCommand();
|
|
|
|
|
command.CommandText = sql;
|
|
|
|
|
int r = command.ExecuteNonQuery();
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NpgsqlConnection CreateConnection()
|
|
|
|
|
{
|
|
|
|
|
NpgsqlConnection conn = new NpgsqlConnection(GetConnectionString());
|
|
|
|
|
conn.Open();
|
|
|
|
|
return conn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|