так красивее
This commit is contained in:
parent
1d6d8da947
commit
664ffc895e
@ -499,92 +499,39 @@ namespace database
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
private Sequence GetSequence(string nameInPg, string nameInApp)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("SELECT sequencename, last_value " +
|
||||
"FROM pg_sequences " +
|
||||
"WHERE sequencename = '" + nameInPg + "_id_seq'", conn);
|
||||
using var reader = cmd.ExecuteReader();
|
||||
if (reader.Read())
|
||||
{
|
||||
return new Sequence
|
||||
{
|
||||
Id = nameInApp,
|
||||
Count = reader.GetInt32(1)
|
||||
};
|
||||
}
|
||||
else
|
||||
return new Sequence
|
||||
{
|
||||
Id = nameInApp,
|
||||
Count = 0
|
||||
};
|
||||
}
|
||||
|
||||
public List<Sequence> GetSequences()
|
||||
{
|
||||
List < Sequence > sequences = new List<Sequence>();
|
||||
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("SELECT sequencename, last_value " +
|
||||
"FROM pg_sequences " +
|
||||
"WHERE sequencename = 'client_id_seq'", conn);
|
||||
using var reader = cmd.ExecuteReader();
|
||||
if (reader.Read())
|
||||
{
|
||||
sequences.Add(new Sequence
|
||||
{
|
||||
Id = "client",
|
||||
Count = reader.GetInt32(1)
|
||||
});
|
||||
}
|
||||
}
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("SELECT sequencename, last_value " +
|
||||
"FROM pg_sequences " +
|
||||
"WHERE sequencename = 'branch_id_seq'", conn);
|
||||
using var reader = cmd.ExecuteReader();
|
||||
if (reader.Read())
|
||||
{
|
||||
sequences.Add(new Sequence
|
||||
{
|
||||
Id = "branch",
|
||||
Count = reader.GetInt32(1)
|
||||
});
|
||||
}
|
||||
}
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("SELECT sequencename, last_value " +
|
||||
"FROM pg_sequences " +
|
||||
"WHERE sequencename = 'carmodel_id_seq'", conn);
|
||||
using var reader = cmd.ExecuteReader();
|
||||
if (reader.Read())
|
||||
{
|
||||
sequences.Add(new Sequence
|
||||
{
|
||||
Id = "car_model",
|
||||
Count = reader.GetInt32(1)
|
||||
});
|
||||
}
|
||||
}
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("SELECT sequencename, last_value " +
|
||||
"FROM pg_sequences " +
|
||||
"WHERE sequencename = 'car_id_seq'", conn);
|
||||
using var reader = cmd.ExecuteReader();
|
||||
if (reader.Read())
|
||||
{
|
||||
sequences.Add(new Sequence
|
||||
{
|
||||
Id = "car",
|
||||
Count = reader.GetInt32(1)
|
||||
});
|
||||
}
|
||||
}
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("SELECT sequencename, last_value " +
|
||||
"FROM pg_sequences " +
|
||||
"WHERE sequencename = 'rental_id_seq'", conn);
|
||||
using var reader = cmd.ExecuteReader();
|
||||
if (reader.Read())
|
||||
{
|
||||
sequences.Add(new Sequence
|
||||
{
|
||||
Id = "rental",
|
||||
Count = reader.GetInt32(1)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return sequences;
|
||||
return new List<Sequence>{
|
||||
GetSequence("client", "client"),
|
||||
GetSequence("branch", "branch"),
|
||||
GetSequence("carmodel", "car_model"),
|
||||
GetSequence("car", "car"),
|
||||
GetSequence("rental", "rental")
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user