本文整理汇总了C++中Statement::Prepare方法的典型用法代码示例。如果您正苦于以下问题:C++ Statement::Prepare方法的具体用法?C++ Statement::Prepare怎么用?C++ Statement::Prepare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Statement
的用法示例。
在下文中一共展示了Statement::Prepare方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetChatrooms
bool Database::GetChatrooms(const Server &Host, std::vector<Chatroom> &Out)
{
Out.clear();
const std::string Query = "SELECT * FROM Chatroom WHERE ServerIP = :ServerIP' AND ServerPort = :ServerPort AND ServerFamily = :ServerFamily";
Statement s;
if (s.Prepare(Inner, Query))
return false;
if (!s.Bind(":ServerIP", Host.Address.GetPrintableIP()) || !s.Bind(":ServerPort", Host.Address.Port) || !s.Bind(":ServerFamily", Host.Address.Family))
return false;
bool MoreData = true;
while (MoreData)
{
if (!s.Step(MoreData))
return false;
Chatroom c;
if (!_GetChatroom(s, c))
return false;
Out.push_back(c);
}
return true;
}
示例2: Open
bool Database::Open(const std::string &Path)
{
if (Inner != nullptr)
Close();
int Err;
if ((Err = sqlite3_initialize()) != SQLITE_OK)
return LogError(sqlite3_errstr(Err), false);
if (Err = sqlite3_open_v2(Path.c_str(), &Inner, SQLITE_OPEN_READWRITE, nullptr) != SQLITE_OK)
{
if (Err = sqlite3_open_v2(Path.c_str(), &Inner, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, nullptr) != SQLITE_OK)
return LogError(sqlite3_errstr(Err), false);
std::vector<std::string> TableStrings;
TableStrings.push_back(User::CreationString);
TableStrings.push_back(Server::CreationString);
TableStrings.push_back(Chatroom::CreationString);
for (unsigned int x = 0; x < TableStrings.size(); x++)
{
Statement s;
if (!s.Prepare(Inner, TableStrings[x]))
return false;
if (!s.Execute())
return false;
}
}
return true;
}
示例3: InsertServer
bool Database::InsertServer(const Server &Server)
{
const std::string Query = "INSERT OR REPLACE INTO Server VALUES (:IP, :Port, :Family, :Name)";
Statement s;
if (!s.Prepare(Inner, Query))
return false;
if (!s.Bind(":IP", Server.Address.GetPrintableIP()) || !s.Bind(":Port", Server.Address.Port) || !s.Bind(":Family", Server.Address.Family) || !s.Bind(":Name", Server.Name))
return false;
if (!s.Execute())
return false;
return true;
}
示例4: InsertUser
bool Database::InsertUser(const User &User)
{
const std::string Query = "INSERT OR REPLACE INTO User VALUES (:Username, :Password)";
Statement s;
if (!s.Prepare(Inner, Query))
return false;
if (!s.Bind(":Username", User.Username) || !s.Bind(":Password", User.Password))
return false;
if (!s.Execute())
return false;
return true;
}
示例5: GetUser
bool Database::GetUser(const std::string &Username, User &Out)
{
const std::string Query = "SELECT * FROM User WHERE Username = :Username";
Statement s;
if (!s.Prepare(Inner, Query))
return false;
if (!s.Bind(":Username", Username.c_str()))
return false;
if (!s.Step())
return false;
if (!_GetUser(s, Out))
return false;
return true;
}
示例6: GetChatroom
bool Database::GetChatroom(const std::string &Name, Chatroom &Out)
{
const std::string Query = "SELECT * FROM Chatroom WHERE Name = :Name";
Statement s;
if (!s.Prepare(Inner, Query))
return false;
if (!s.Bind(":Name", Name))
return false;
if (!s.Step())
return false;
if (!_GetChatroom(s, Out))
return false;
return true;
}
示例7: GetServer
bool Database::GetServer(const Net::Address Address, Server &Out)
{
const std::string Query = "SELECT * FROM Server WHERE Family = :Family AND IP = :IP AND Port = :Port";
Statement s;
if (!s.Prepare(Inner, Query))
return false;
if (!s.Bind(":Family", Address.Family) || !s.Bind(":IP", Address.GetPrintableIP()) || !s.Bind(":Port", Address.Port))
return false;
if (!s.Step())
return false;
if (!_GetServer(s, Out))
return false;
return true;
}
示例8: InsertChatroom
bool Database::InsertChatroom(const Chatroom &Chatroom)
{
const std::string Query = "INSERT OR REPLACE INTO Chatroom VALUES (:Name, :OwnerUsername, :ServerIP, :ServerPort, :ServerFamily, :Password, :Description)";
Statement s;
if (!s.Prepare(Inner, Query))
return false;
if (!s.Bind(":Name", Chatroom.Name) || !s.Bind(":OwnerUsername", Chatroom.OwnerUsername) || !s.Bind(":ServerIP", Chatroom.ServerAddress.GetPrintableIP()) ||
!s.Bind(":ServerPort", Chatroom.ServerAddress.Port) || !s.Bind(":ServerFamily", Chatroom.ServerAddress.Family))
return false;
if (!Chatroom.Password.Null)
{
if (!s.Bind(":Password", Chatroom.Password.Value))
return false;
}
else
{
if (!s.BindNull(":Password"))
return false;
}
if (!Chatroom.Description.Null)
{
if (!s.Bind(":Description", Chatroom.Description.Value))
return false;
}
else
{
if (!s.BindNull(":Description"))
return false;
}
if (!s.Execute())
return false;
return true;
}
示例9: GetUsers
bool Database::GetUsers(std::vector<User> &Users)
{
Users.clear();
const std::string Query = "SELECT * FROM User";
Statement s;
if (!s.Prepare(Inner, Query))
return false;
bool MoreData = true;
while (MoreData)
{
if (!s.Step(MoreData))
return false;
User u;
if (!_GetUser(s, u))
return false;
Users.push_back(u);
}
return true;
}
示例10: GetServers
bool Database::GetServers(std::vector<Server> &Servers)
{
Servers.clear();
const std::string Query = "SELECT * FROM Server";
Statement s;
if (!s.Prepare(Inner, Query))
return false;
bool MoreData = true;
while (MoreData)
{
if (!s.Step(MoreData))
return false;
Server Out;
if (!_GetServer(s, Out))
return false;
Servers.push_back(Out);
}
return true;
}