void CAccountManager::Save ( CAccount* pAccount, bool bCheckForErrors ) { SString strName = pAccount->GetName(); SString strPassword = pAccount->GetPasswordHash(); SString strHttpPassAppend = pAccount->GetHttpPassAppend(); SString strIP = pAccount->GetIP(); SString strSerial = pAccount->GetSerial(); unsigned int iID = pAccount->GetID(); m_pDatabaseManager->Execf ( m_hDbConnection, "INSERT OR IGNORE INTO accounts (id, name, ip, serial, password) VALUES(?,?,?,?,?)", SQLITE_INTEGER, iID, SQLITE_TEXT, strName.c_str (), SQLITE_TEXT, strIP.c_str (), SQLITE_TEXT, strSerial.c_str (), SQLITE_TEXT, strPassword.c_str () ); SString strQuery; strQuery += m_pDatabaseManager->PrepareStringf(m_hDbConnection, "UPDATE accounts SET ip=?", SQLITE_TEXT, *strIP); if (!strSerial.empty()) strQuery += m_pDatabaseManager->PrepareStringf(m_hDbConnection, ",serial=?", SQLITE_TEXT, *strSerial); strQuery += m_pDatabaseManager->PrepareStringf(m_hDbConnection, ",password=?, httppass=? WHERE name=?", SQLITE_TEXT, *strPassword, SQLITE_TEXT, *strHttpPassAppend, SQLITE_TEXT, *strName); if (bCheckForErrors) { m_pDatabaseManager->QueryWithCallback(m_hDbConnection, StaticDbCallback, this, strQuery); } else { m_pDatabaseManager->Exec(m_hDbConnection, strQuery); } SaveAccountSerialUsage( pAccount ); //Set changed since saved to false pAccount->SetChanged( false ); }
void CAccountManager::Save ( CAccount* pAccount, bool bCheckForErrors ) { SString strName = pAccount->GetName(); SString strPassword = pAccount->GetPasswordHash(); SString strIP = pAccount->GetIP(); SString strSerial = pAccount->GetSerial(); unsigned int iID = pAccount->GetID(); m_pDatabaseManager->Execf ( m_hDbConnection, "INSERT OR IGNORE INTO accounts (id, name, ip, serial, password) VALUES(?,?,?,?,?)", SQLITE_INTEGER, iID, SQLITE_TEXT, strName.c_str (), SQLITE_TEXT, strIP.c_str (), SQLITE_TEXT, strSerial.c_str (), SQLITE_TEXT, strPassword.c_str () ); if ( bCheckForErrors ) { if ( strSerial != "" ) m_pDatabaseManager->QueryWithCallbackf ( m_hDbConnection, StaticDbCallback, this, "UPDATE accounts SET ip=?, serial=?, password=? WHERE name=?", SQLITE_TEXT, strIP.c_str (), SQLITE_TEXT, strSerial.c_str (), SQLITE_TEXT, strPassword.c_str (), SQLITE_TEXT, strName.c_str () ); else //If we don't have a serial then IP and password will suffice m_pDatabaseManager->QueryWithCallbackf ( m_hDbConnection, StaticDbCallback, this, "UPDATE accounts SET ip=?, password=? WHERE name=?", SQLITE_TEXT, strIP.c_str (), SQLITE_TEXT, strPassword.c_str (), SQLITE_TEXT, strName.c_str () ); } else { if ( strSerial != "" ) m_pDatabaseManager->Execf ( m_hDbConnection, "UPDATE accounts SET ip=?, serial=?, password=? WHERE name=?", SQLITE_TEXT, strIP.c_str (), SQLITE_TEXT, strSerial.c_str (), SQLITE_TEXT, strPassword.c_str (), SQLITE_TEXT, strName.c_str () ); else //If we don't have a serial then IP and password will suffice m_pDatabaseManager->Execf ( m_hDbConnection, "UPDATE accounts SET ip=?, password=? WHERE name=?", SQLITE_TEXT, strIP.c_str (), SQLITE_TEXT, strPassword.c_str (), SQLITE_TEXT, strName.c_str () ); } SaveAccountSerialUsage( pAccount ); //Set changed since saved to false pAccount->SetChanged( false ); }