forked from FarmMaps/FarmMapsApiClient
Added project FarmmapsBulkSatDownload
This commit is contained in:
47
FarmmapsBulkSatDownload/Models/DB.cs
Normal file
47
FarmmapsBulkSatDownload/Models/DB.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Npgsql;
|
||||
|
||||
namespace FarmmapsApi.Services
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user