added config parameter: db_postgresql_smaller_than_10
default false if true then we are not using ROW() statements in sql queries git-svn-id: svn://ttmath.org/publicrep/winix/trunk@1099 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
fd421c54e3
commit
b01db89942
|
@ -214,6 +214,7 @@ bool App::Init()
|
||||||
{
|
{
|
||||||
db_conn.SetConnParam(config.db_database, config.db_user, config.db_pass);
|
db_conn.SetConnParam(config.db_database, config.db_user, config.db_pass);
|
||||||
db_conn.WaitForConnection();
|
db_conn.WaitForConnection();
|
||||||
|
db.PostgreSQLsmallerThan10(config.db_postgresql_smaller_than_10);
|
||||||
db.LogQueries(config.log_db_query);
|
db.LogQueries(config.log_db_query);
|
||||||
|
|
||||||
cur.request->Clear();
|
cur.request->Clear();
|
||||||
|
|
|
@ -187,6 +187,8 @@ void Config::AssignValues(bool stdout_is_closed)
|
||||||
db_database = Text(L"db_database");
|
db_database = Text(L"db_database");
|
||||||
db_user = Text(L"db_user");
|
db_user = Text(L"db_user");
|
||||||
db_pass = Text(L"db_pass");
|
db_pass = Text(L"db_pass");
|
||||||
|
db_postgresql_smaller_than_10 = Bool(L"db_postgresql_smaller_than_10", false);
|
||||||
|
|
||||||
item_url_empty = Text(L"item_url_empty");
|
item_url_empty = Text(L"item_url_empty");
|
||||||
|
|
||||||
url_proto = Text(L"url_proto", L"http://");
|
url_proto = Text(L"url_proto", L"http://");
|
||||||
|
|
|
@ -188,6 +188,11 @@ public:
|
||||||
std::wstring db_user;
|
std::wstring db_user;
|
||||||
std::wstring db_pass;
|
std::wstring db_pass;
|
||||||
|
|
||||||
|
// is the PostgreSQL later than 10
|
||||||
|
// default false
|
||||||
|
// if true then we are not using ROW() statements in sql query
|
||||||
|
bool db_postgresql_smaller_than_10;
|
||||||
|
|
||||||
// the name of the cookie which has the session identifier
|
// the name of the cookie which has the session identifier
|
||||||
std::wstring http_session_id_name;
|
std::wstring http_session_id_name;
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,19 @@ namespace Winix
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
void Db::PostgreSQLsmallerThan10(bool is_smaller_than_10)
|
||||||
|
{
|
||||||
|
is_postgresql_smaller_than_10 = is_smaller_than_10;
|
||||||
|
|
||||||
|
if( is_postgresql_smaller_than_10 )
|
||||||
|
{
|
||||||
|
postgrsql_row_statement.clear();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
postgrsql_row_statement = L"ROW";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Db::GetUserPass(const std::wstring & login, long & user_id, UserPass & up)
|
bool Db::GetUserPass(const std::wstring & login, long & user_id, UserPass & up)
|
||||||
|
@ -154,7 +167,7 @@ Error Db::ChangeUserPass(long user_id, const UserPass & up)
|
||||||
{
|
{
|
||||||
query.Clear();
|
query.Clear();
|
||||||
query << R("update core.user set(has_pass, password, pass_encrypted,"
|
query << R("update core.user set(has_pass, password, pass_encrypted,"
|
||||||
"pass_type, pass_hash_salted) = ROW(")
|
"pass_type, pass_hash_salted) = ") << R(postgrsql_row_statement) << R("(")
|
||||||
<< up.has_pass;
|
<< up.has_pass;
|
||||||
|
|
||||||
// for safety
|
// for safety
|
||||||
|
@ -178,7 +191,7 @@ return DoCommand(query);
|
||||||
Error Db::ChangeUserEnv(long user_id, const PT::Space & space)
|
Error Db::ChangeUserEnv(long user_id, const PT::Space & space)
|
||||||
{
|
{
|
||||||
query.Clear();
|
query.Clear();
|
||||||
query << R("update core.user set(env) = ROW(")
|
query << R("update core.user set(env) = ") << R(postgrsql_row_statement) << R("(")
|
||||||
<< space
|
<< space
|
||||||
<< R(") where id = ")
|
<< R(") where id = ")
|
||||||
<< user_id
|
<< user_id
|
||||||
|
@ -191,7 +204,7 @@ return DoCommand(query);
|
||||||
Error Db::ChangeUserAdminEnv(long user_id, const PT::Space & space)
|
Error Db::ChangeUserAdminEnv(long user_id, const PT::Space & space)
|
||||||
{
|
{
|
||||||
query.Clear();
|
query.Clear();
|
||||||
query << R("update core.user set(aenv) = ROW(")
|
query << R("update core.user set(aenv) = ") << R(postgrsql_row_statement) << R("(")
|
||||||
<< space
|
<< space
|
||||||
<< R(") where id = ")
|
<< R(") where id = ")
|
||||||
<< user_id
|
<< user_id
|
||||||
|
@ -204,7 +217,7 @@ return DoCommand(query);
|
||||||
Error Db::ChangeUserStatus(long user_id, int status)
|
Error Db::ChangeUserStatus(long user_id, int status)
|
||||||
{
|
{
|
||||||
query.Clear();
|
query.Clear();
|
||||||
query << R("update core.user set(status) = ROW(")
|
query << R("update core.user set(status) = ") << R(postgrsql_row_statement) << R("(")
|
||||||
<< status
|
<< status
|
||||||
<< R(") where id = ")
|
<< R(") where id = ")
|
||||||
<< user_id
|
<< user_id
|
||||||
|
@ -218,7 +231,7 @@ return DoCommand(query);
|
||||||
Error Db::ChangeUserEmail(long user_id, const std::wstring & email)
|
Error Db::ChangeUserEmail(long user_id, const std::wstring & email)
|
||||||
{
|
{
|
||||||
query.Clear();
|
query.Clear();
|
||||||
query << R("update core.user set(email) = ROW(")
|
query << R("update core.user set(email) = ") << R(postgrsql_row_statement) << R("(")
|
||||||
<< email
|
<< email
|
||||||
<< R(") where id = ")
|
<< R(") where id = ")
|
||||||
<< user_id
|
<< user_id
|
||||||
|
@ -231,7 +244,7 @@ return DoCommand(query);
|
||||||
Error Db::ChangeUserLocale(long user_id, size_t locale_id)
|
Error Db::ChangeUserLocale(long user_id, size_t locale_id)
|
||||||
{
|
{
|
||||||
query.Clear();
|
query.Clear();
|
||||||
query << R("update core.user set(locale_id) = ROW(")
|
query << R("update core.user set(locale_id) = ") << R(postgrsql_row_statement) << R("(")
|
||||||
<< locale_id
|
<< locale_id
|
||||||
<< R(") where id = ")
|
<< R(") where id = ")
|
||||||
<< user_id
|
<< user_id
|
||||||
|
@ -244,7 +257,7 @@ return DoCommand(query);
|
||||||
Error Db::ChangeUserTimeZone(long user_id, size_t time_zone_id)
|
Error Db::ChangeUserTimeZone(long user_id, size_t time_zone_id)
|
||||||
{
|
{
|
||||||
query.Clear();
|
query.Clear();
|
||||||
query << R("update core.user set(time_zone_id) = ROW(")
|
query << R("update core.user set(time_zone_id) = ") << R(postgrsql_row_statement) << R("(")
|
||||||
<< time_zone_id
|
<< time_zone_id
|
||||||
<< R(") where id = ")
|
<< R(") where id = ")
|
||||||
<< user_id
|
<< user_id
|
||||||
|
@ -455,7 +468,7 @@ return EndTrans(result);
|
||||||
Error Db::IncrementContentRef(long content_id)
|
Error Db::IncrementContentRef(long content_id)
|
||||||
{
|
{
|
||||||
query.Clear();
|
query.Clear();
|
||||||
query << R("update core.content set (ref) = ROW(ref + 1) where id = ")
|
query << R("update core.content set (ref) = ") << R(postgrsql_row_statement) << R("(ref + 1) where id = ")
|
||||||
<< content_id
|
<< content_id
|
||||||
<< R(";");
|
<< R(";");
|
||||||
|
|
||||||
|
@ -466,7 +479,7 @@ return DoCommand(query);
|
||||||
Error Db::DecrementContentRef(long content_id)
|
Error Db::DecrementContentRef(long content_id)
|
||||||
{
|
{
|
||||||
query.Clear();
|
query.Clear();
|
||||||
query << R("update core.content set (ref) = ROW(ref - 1) where id = ")
|
query << R("update core.content set (ref) = ") << R(postgrsql_row_statement) << R("(ref - 1) where id = ")
|
||||||
<< content_id
|
<< content_id
|
||||||
<< R(";");
|
<< R(";");
|
||||||
|
|
||||||
|
@ -507,7 +520,7 @@ Error Db::EditItemInItem(Item & item, bool with_url)
|
||||||
if( with_url )
|
if( with_url )
|
||||||
query << R(", url");
|
query << R(", url");
|
||||||
|
|
||||||
query << R(") = ROW(")
|
query << R(") = ") << R(postgrsql_row_statement) << R("(")
|
||||||
<< item.user_id
|
<< item.user_id
|
||||||
<< item.modification_user_id
|
<< item.modification_user_id
|
||||||
<< item.group_id
|
<< item.group_id
|
||||||
|
@ -565,7 +578,7 @@ Error Db::EditItemInContent(Item & item)
|
||||||
// we don't change 'ref' here
|
// we don't change 'ref' here
|
||||||
query.Clear();
|
query.Clear();
|
||||||
query << R("update core.content set (content, content_type, file_path, file_fs, "
|
query << R("update core.content set (content, content_type, file_path, file_fs, "
|
||||||
"file_type, has_thumb, hash, hash_type, file_size, modify_index) = ROW(")
|
"file_type, has_thumb, hash, hash_type, file_size, modify_index) = ") << R(postgrsql_row_statement) << R("(")
|
||||||
<< item.content
|
<< item.content
|
||||||
<< static_cast<int>(item.content_type)
|
<< static_cast<int>(item.content_type)
|
||||||
<< item.file_path
|
<< item.file_path
|
||||||
|
@ -709,7 +722,7 @@ Error Db::EditLinkItem(long id, const std::wstring & link_to, int link_redirect)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
query.Clear();
|
query.Clear();
|
||||||
query << R("update core.item set (link_to, link_redirect) = ROW(")
|
query << R("update core.item set (link_to, link_redirect) = ") << R(postgrsql_row_statement) << R("(")
|
||||||
<< link_to
|
<< link_to
|
||||||
<< link_redirect
|
<< link_redirect
|
||||||
<< R(") where id=")
|
<< R(") where id=")
|
||||||
|
@ -744,7 +757,7 @@ Error Db::EditTemplateItemById(long id, const std::wstring & new_html_template)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
query.Clear();
|
query.Clear();
|
||||||
query << R("update core.item set (template) = ROW(")
|
query << R("update core.item set (template) = ") << R(postgrsql_row_statement) << R("(")
|
||||||
<< new_html_template
|
<< new_html_template
|
||||||
<< R(") where id=")
|
<< R(") where id=")
|
||||||
<< id
|
<< id
|
||||||
|
@ -774,7 +787,7 @@ return result;
|
||||||
Error Db::EditSortIndexItemById(long id, int sort_index)
|
Error Db::EditSortIndexItemById(long id, int sort_index)
|
||||||
{
|
{
|
||||||
query.Clear();
|
query.Clear();
|
||||||
query << R("update core.item set (sort_index) = ROW(")
|
query << R("update core.item set (sort_index) = ") << R(postgrsql_row_statement) << R("(")
|
||||||
<< sort_index
|
<< sort_index
|
||||||
<< R(") where id=")
|
<< R(") where id=")
|
||||||
<< id
|
<< id
|
||||||
|
@ -1236,7 +1249,7 @@ Error Db::EditPrivById(Item & item, long id)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
query.Clear();
|
query.Clear();
|
||||||
query << R("update core.item set (user_id, modification_user_id, group_id, privileges, guest_name) = ROW(")
|
query << R("update core.item set (user_id, modification_user_id, group_id, privileges, guest_name) = ") << R(postgrsql_row_statement) << R("(")
|
||||||
<< item.user_id
|
<< item.user_id
|
||||||
<< item.modification_user_id
|
<< item.modification_user_id
|
||||||
<< item.group_id
|
<< item.group_id
|
||||||
|
@ -1271,7 +1284,7 @@ Error Db::EditParentUrlById(Item & item, long id)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
query.Clear();
|
query.Clear();
|
||||||
query << R("update core.item set (parent_id, url) = ROW(") << item.parent_id;
|
query << R("update core.item set (parent_id, url) = ") << R(postgrsql_row_statement) << R("(") << item.parent_id;
|
||||||
|
|
||||||
url_without_id = AddItemCreateUrlSubject(item);
|
url_without_id = AddItemCreateUrlSubject(item);
|
||||||
|
|
||||||
|
@ -1313,7 +1326,7 @@ Error Db::EditFileById(const Item & item, long id)
|
||||||
throw Error(WINIX_ERR_NO_ITEM);
|
throw Error(WINIX_ERR_NO_ITEM);
|
||||||
|
|
||||||
query.Clear();
|
query.Clear();
|
||||||
query << R("update core.content set (file_path, file_fs, file_type, has_thumb, hash, hash_type, file_size) = ROW(")
|
query << R("update core.content set (file_path, file_fs, file_type, has_thumb, hash, hash_type, file_size) = ") << R(postgrsql_row_statement) << R("(")
|
||||||
<< item.file_path
|
<< item.file_path
|
||||||
<< item.file_fs
|
<< item.file_fs
|
||||||
<< item.file_type
|
<< item.file_type
|
||||||
|
@ -1353,7 +1366,7 @@ Error Db::EditHasThumbById(bool has_thumb, long id)
|
||||||
throw Error(WINIX_ERR_NO_ITEM);
|
throw Error(WINIX_ERR_NO_ITEM);
|
||||||
|
|
||||||
query.Clear();
|
query.Clear();
|
||||||
query << R("update core.content set (has_thumb) = ROW(")
|
query << R("update core.content set (has_thumb) = ") << R(postgrsql_row_statement) << R("(")
|
||||||
<< static_cast<int>(has_thumb)
|
<< static_cast<int>(has_thumb)
|
||||||
<< R(") where id=") << content_id << R(";");
|
<< R(") where id=") << content_id << R(";");
|
||||||
|
|
||||||
|
@ -1375,7 +1388,7 @@ return EndTrans(result);
|
||||||
Error Db::EditMetaById(const PT::Space & meta, long id)
|
Error Db::EditMetaById(const PT::Space & meta, long id)
|
||||||
{
|
{
|
||||||
query.Clear();
|
query.Clear();
|
||||||
query << R("update core.item set (meta) = ROW(")
|
query << R("update core.item set (meta) = ") << R(postgrsql_row_statement) << R("(")
|
||||||
<< meta
|
<< meta
|
||||||
<< R(") where id=")
|
<< R(") where id=")
|
||||||
<< id
|
<< id
|
||||||
|
@ -1388,7 +1401,7 @@ return DoCommand(query);
|
||||||
Error Db::EditAdminMetaById(const PT::Space & ameta, long id)
|
Error Db::EditAdminMetaById(const PT::Space & ameta, long id)
|
||||||
{
|
{
|
||||||
query.Clear();
|
query.Clear();
|
||||||
query << R("update core.item set (ameta) = ROW(")
|
query << R("update core.item set (ameta) = ") << R(postgrsql_row_statement) << R("(")
|
||||||
<< ameta
|
<< ameta
|
||||||
<< R(") where id=")
|
<< R(") where id=")
|
||||||
<< id
|
<< id
|
||||||
|
@ -1408,7 +1421,7 @@ Error Db::EditSubjectById(Item & item, long id)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
query.Clear();
|
query.Clear();
|
||||||
query << R("update core.item set (subject) = ROW(")
|
query << R("update core.item set (subject) = ") << R(postgrsql_row_statement) << R("(")
|
||||||
<< item.subject
|
<< item.subject
|
||||||
<< R(") where id=")
|
<< R(") where id=")
|
||||||
<< id
|
<< id
|
||||||
|
@ -1440,7 +1453,7 @@ Error Db::DelDirById(long id)
|
||||||
{
|
{
|
||||||
// decrementing ref in core.content
|
// decrementing ref in core.content
|
||||||
query.Clear();
|
query.Clear();
|
||||||
query << R("update core.content set (ref) = ROW(ref - 1) where content.id in "
|
query << R("update core.content set (ref) = ") << R(postgrsql_row_statement) << R("(ref - 1) where content.id in "
|
||||||
"(select content_id from core.item where type=1 and parent_id=")
|
"(select content_id from core.item where type=1 and parent_id=")
|
||||||
<< id
|
<< id
|
||||||
<< R(");");
|
<< R(");");
|
||||||
|
|
|
@ -67,8 +67,10 @@ public:
|
||||||
|
|
||||||
Db() : item_cols(*this)
|
Db() : item_cols(*this)
|
||||||
{
|
{
|
||||||
|
is_postgresql_smaller_than_10 = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PostgreSQLsmallerThan10(bool is_smaller_than_10);
|
||||||
|
|
||||||
bool GetUserPass(const std::wstring & login, long & user_id, UserPass & up);
|
bool GetUserPass(const std::wstring & login, long & user_id, UserPass & up);
|
||||||
Error AddUser(User & user, const UserPass & up);
|
Error AddUser(User & user, const UserPass & up);
|
||||||
|
@ -138,6 +140,8 @@ protected:
|
||||||
std::wstring iq_id_list;
|
std::wstring iq_id_list;
|
||||||
DbItemColumns item_cols;
|
DbItemColumns item_cols;
|
||||||
|
|
||||||
|
bool is_postgresql_smaller_than_10;
|
||||||
|
std::wstring postgrsql_row_statement;
|
||||||
|
|
||||||
bool AddItemCreateUrlSubject(Item & item);
|
bool AddItemCreateUrlSubject(Item & item);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue