summaryrefslogtreecommitdiff
path: root/plugins/Import/src/dbrw/dbintf.cpp
blob: 137b79aaa9820008d20fe684f2b82cd0e3dde7c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*

Import plugin for Miranda NG

Copyright (c) 2012-18 Miranda NG team (https://miranda-ng.org)

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

*/

#include "../stdafx.h"

CDbxSQLite::CDbxSQLite()
	: sql_prepare_len(0)
{
	m_hAPCWindow = CreateWindowEx(0, L"STATIC", NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);

	sql_prepare_add(ctc_stmts, ctc_stmts_prep, SQL_CTC_STMT_NUM);
	sql_prepare_add(evt_stmts, evt_stmts_prep, SQL_EVT_STMT_NUM);
	sql_prepare_add(set_stmts, set_stmts_prep, SQL_SET_STMT_NUM);
}

CDbxSQLite::~CDbxSQLite()
{
	sql_close(m_sqlite);

	for (int i = 0; i < sql_prepare_len; i++)
		sql_finalize(*sql_prepare_stmt[i]);
	mir_free(sql_prepare_text);
	mir_free(sql_prepare_stmt);
	DestroyWindow(m_hAPCWindow);
}

int CDbxSQLite::Open(const wchar_t *profile)
{
	T2Utf path(profile);
	if (sql_open(path, &m_sqlite) != SQLITE_OK)
		return 1;

	//utils_vacuum_check();
	{
		sql_exec(m_sqlite, "BEGIN TRANSACTION;");
		sql_exec(m_sqlite, "PRAGMA locking_mode = EXCLUSIVE;");
		sql_exec(m_sqlite, "PRAGMA synchronous = NORMAL;");
		sql_exec(m_sqlite, "PRAGMA cache_size = 6000;");
		sql_exec(m_sqlite, "PRAGMA temp_store = MEMORY;");
		sql_exec(m_sqlite, "COMMIT;");
	}

	sql_prepare_statements();

	FillContacts();

	return 0;
}

STDMETHODIMP_(void) CDbxSQLite::SetCacheSafetyMode(BOOL safeMode)
{
	if (safeMode)
		sql_exec(m_sqlite, "PRAGMA synchronous = NORMAL;");
	else
		sql_exec(m_sqlite, "PRAGMA synchronous = OFF;");
}

STDMETHODIMP_(BOOL) CDbxSQLite::MetaMergeHistory(DBCachedContact*, DBCachedContact*)
{
	return FALSE;
}

STDMETHODIMP_(BOOL) CDbxSQLite::MetaSplitHistory(DBCachedContact*, DBCachedContact*)
{
	return FALSE;
}