forked from FarmMaps/FarmMapsApiClient
48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
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;
|
|
}
|
|
|
|
}
|
|
}
|