2 * Copyright 2012 Samsung Electronics Co., Ltd
\r
4 * Licensed under the Flora License, Version 1.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.tizenopensource.org/license
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
19 using namespace std;
\r
21 #include "browser-bookmark-db.h"
\r
23 #define BOOKMARK_NORMAL 0
\r
24 #define BOOKMARK_FOLDER 1
\r
26 sqlite3* Browser_Bookmark_DB::m_db_descriptor = NULL;
\r
28 Browser_Bookmark_DB::Browser_Bookmark_DB(void)
\r
30 BROWSER_LOGD("[%s]", __func__);
\r
33 Browser_Bookmark_DB::~Browser_Bookmark_DB(void)
\r
35 BROWSER_LOGD("[%s]", __func__);
\r
38 Eina_Bool Browser_Bookmark_DB::_open_db(void)
\r
40 BROWSER_LOGD("[%s]", __func__);
\r
41 int error = db_util_open(BROWSER_BOOKMARK_DB_PATH, &m_db_descriptor, DB_UTIL_REGISTER_HOOK_METHOD);
\r
42 if (error != SQLITE_OK) {
\r
43 db_util_close(m_db_descriptor);
\r
44 m_db_descriptor = NULL;
\r
51 Eina_Bool Browser_Bookmark_DB::_close_db(void)
\r
53 BROWSER_LOGD("[%s]", __func__);
\r
54 if (m_db_descriptor)
\r
56 int error = db_util_close(m_db_descriptor);
\r
57 if (error != SQLITE_OK) {
\r
58 BROWSER_LOGE("db_util_close error");
\r
59 m_db_descriptor = NULL;
\r
62 m_db_descriptor = NULL;
\r
68 Eina_Bool Browser_Bookmark_DB::_get_last_index(int folder_id, int *last_index)
\r
70 if (_open_db() == EINA_FALSE)
\r
73 std::string query = "select sequence from bookmarks where parent=? order by sequence desc";
\r
75 sqlite3_stmt *sqlite3_stmt = NULL;
\r
76 int error = sqlite3_prepare_v2(m_db_descriptor, query.c_str(), -1, &sqlite3_stmt, NULL);
\r
77 if (error != SQLITE_OK) {
\r
78 BROWSER_LOGD("SQL error=%d", error);
\r
79 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
80 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
85 if (sqlite3_bind_int(sqlite3_stmt, 1, folder_id) != SQLITE_OK)
\r
86 BROWSER_LOGE("sqlite3_bind_int is failed.\n");
\r
88 if ((error = sqlite3_step(sqlite3_stmt)) == SQLITE_ROW || error == SQLITE_DONE)
\r
89 *last_index = sqlite3_column_int(sqlite3_stmt, 0);
\r
91 BROWSER_LOGE("sqlite3_step is failed. error=%d\n", error);
\r
93 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
94 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
96 if (_close_db() == EINA_FALSE)
\r
97 BROWSER_LOGE("_close_db is failed.");
\r
99 return (error == SQLITE_DONE || error == SQLITE_ROW);
\r
102 Eina_Bool Browser_Bookmark_DB::delete_bookmark(int bookmark_id)
\r
104 if (_open_db() == EINA_FALSE)
\r
107 sqlite3_stmt *sqlite3_stmt = NULL;
\r
108 int error = sqlite3_prepare_v2(m_db_descriptor, "delete from bookmarks where id=?",
\r
109 -1, &sqlite3_stmt, NULL);
\r
110 if (error != SQLITE_OK) {
\r
111 BROWSER_LOGD("SQL error=%d", error);
\r
112 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
113 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
118 if (sqlite3_bind_int(sqlite3_stmt, 1, bookmark_id) != SQLITE_OK)
\r
119 BROWSER_LOGE("sqlite3_bind_int is failed.\n");
\r
121 error = sqlite3_step(sqlite3_stmt);
\r
122 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
123 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
125 if (error != SQLITE_OK && error != SQLITE_DONE) {
\r
126 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
127 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
132 if (_close_db() == EINA_FALSE)
\r
133 BROWSER_LOGE("_close_db is failed.");
\r
135 return (error == SQLITE_DONE);
\r
138 Eina_Bool Browser_Bookmark_DB::delete_folder(int folder_id)
\r
140 delete_bookmark(folder_id);
\r
142 if (_open_db() == EINA_FALSE)
\r
145 sqlite3_stmt *sqlite3_stmt = NULL;
\r
146 int error = sqlite3_prepare_v2(m_db_descriptor, "select id, type from bookmarks where parent=?",
\r
147 -1, &sqlite3_stmt, NULL);
\r
148 if (error != SQLITE_OK) {
\r
149 BROWSER_LOGD("SQL error=%d", error);
\r
150 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
151 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
156 if (sqlite3_bind_int(sqlite3_stmt, 1, folder_id) != SQLITE_OK)
\r
157 BROWSER_LOGE("sqlite3_bind_int is failed.\n");
\r
159 std::vector<bookmark_item_type> item_type;
\r
160 while ((error = sqlite3_step(sqlite3_stmt)) == SQLITE_ROW) {
\r
161 bookmark_item_type type;
\r
162 type.id = sqlite3_column_int(sqlite3_stmt, 0);
\r
163 type.is_folder = (sqlite3_column_int(sqlite3_stmt, 1) == BOOKMARK_FOLDER);
\r
164 item_type.push_back(type);
\r
167 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
168 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
172 for (std::vector<bookmark_item_type>::iterator iter = item_type.begin()
\r
173 ; iter != item_type.end() ; iter++) {
\r
174 if(iter->is_folder)
\r
175 delete_folder(iter->id);
\r
177 delete_bookmark(iter->id);
\r
183 Eina_Bool Browser_Bookmark_DB::get_bookmark_id_by_title_url(int folder_id, const char *title,
\r
184 const char *url, int *bookmark_id)
\r
186 if (_open_db() == EINA_FALSE)
\r
189 sqlite3_stmt *sqlite3_stmt = NULL;
\r
190 int error = sqlite3_prepare_v2(m_db_descriptor, "select id from bookmarks where parent=? and title=?",
\r
191 -1, &sqlite3_stmt, NULL);
\r
192 if (error != SQLITE_OK) {
\r
193 BROWSER_LOGD("SQL error=%d", error);
\r
194 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
195 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
200 if (sqlite3_bind_int(sqlite3_stmt, 1, folder_id) != SQLITE_OK)
\r
201 BROWSER_LOGE("sqlite3_bind_int is failed.\n");
\r
202 if (sqlite3_bind_text(sqlite3_stmt, 2, title, -1, NULL) != SQLITE_OK)
\r
203 BROWSER_LOGE("sqlite3_bind_text is failed.\n");
\r
205 error = sqlite3_step(sqlite3_stmt);
\r
206 if (error != SQLITE_ROW) {
\r
207 BROWSER_LOGD("SQL error=%d", error);
\r
208 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
209 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
214 *bookmark_id = sqlite3_column_int(sqlite3_stmt, 0);
\r
216 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
217 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
221 return (error == SQLITE_ROW);
\r
224 Eina_Bool Browser_Bookmark_DB::save_folder(const char* folder_name)
\r
226 int last_index = 0;
\r
227 Eina_Bool get_last_index_result = EINA_TRUE;
\r
228 if (!_get_last_index(BROWSER_BOOKMARK_MAIN_FOLDER_ID, &last_index)) {
\r
229 BROWSER_LOGE("_get_last_index failed.\n");
\r
230 get_last_index_result = EINA_FALSE;
\r
233 if (_open_db() == EINA_FALSE)
\r
236 sqlite3_stmt *sqlite3_stmt = NULL;
\r
237 int error = sqlite3_prepare_v2(m_db_descriptor, "insert into bookmarks (type, parent, title, creationdate, sequence, updatedate, editable) values (?, ?, ?, DATETIME('now'), ?, DATETIME('now'), 1)",
\r
238 -1, &sqlite3_stmt, NULL);
\r
239 if (error != SQLITE_OK) {
\r
240 BROWSER_LOGD("SQL error=%d", error);
\r
241 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
242 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
247 if (sqlite3_bind_int(sqlite3_stmt, 1, 1) != SQLITE_OK)
\r
248 BROWSER_LOGE("sqlite3_bind_int is failed.\n");
\r
249 if (sqlite3_bind_int(sqlite3_stmt, 2, BROWSER_BOOKMARK_MAIN_FOLDER_ID) != SQLITE_OK)
\r
250 BROWSER_LOGE("sqlite3_bind_int is failed.\n");
\r
251 if (sqlite3_bind_text(sqlite3_stmt, 3, folder_name, -1, NULL) != SQLITE_OK)
\r
252 BROWSER_LOGE("sqlite3_bind_text is failed.\n");
\r
254 if (get_last_index_result) {
\r
255 if (sqlite3_bind_int(sqlite3_stmt, 4, last_index + 1) != SQLITE_OK)
\r
256 BROWSER_LOGE("sqlite3_bind_int is failed.\n");
\r
258 if (sqlite3_bind_int(sqlite3_stmt, 4, 1) != SQLITE_OK)
\r
259 BROWSER_LOGE("sqlite3_bind_int is failed.\n");
\r
262 error = sqlite3_step(sqlite3_stmt);
\r
264 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
265 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
269 return (error == SQLITE_DONE);
\r
272 Eina_Bool Browser_Bookmark_DB::save_bookmark(int folder_id, const char* title, const char* url)
\r
274 if (!title || !url)
\r
277 int last_index = 0;
\r
278 Eina_Bool get_last_index_result = EINA_TRUE;
\r
279 if (!_get_last_index(folder_id, &last_index)) {
\r
280 BROWSER_LOGE("_get_last_index failed.\n");
\r
281 get_last_index_result = EINA_FALSE;
\r
284 if (_open_db() == EINA_FALSE)
\r
287 sqlite3_stmt *sqlite3_stmt = NULL;
\r
288 int error = sqlite3_prepare_v2(m_db_descriptor, "insert into bookmarks (type, parent, address, title, creationdate, sequence, updatedate, editable) values (?, ?, ?, ?, DATETIME('now'), ?, DATETIME('now'), 1)",
\r
289 -1, &sqlite3_stmt, NULL);
\r
290 if (error != SQLITE_OK) {
\r
291 BROWSER_LOGD("SQL error=%d", error);
\r
292 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
293 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
298 std::string title_to_save = "";
\r
299 std::string url_to_save = "";
\r
301 title_to_save = title;
\r
302 if (title_to_save.size() >= BROWSER_MAX_TITLE_LEN)
\r
303 title_to_save.resize(BROWSER_MAX_TITLE_LEN - 1);
\r
305 if (url_to_save.size() >= BROWSER_MAX_URL_LEN)
\r
306 url_to_save.resize(BROWSER_MAX_URL_LEN - 1);
\r
308 if (sqlite3_bind_int(sqlite3_stmt, 1, 0) != SQLITE_OK)
\r
309 BROWSER_LOGE("sqlite3_bind_int is failed.\n");
\r
310 if (sqlite3_bind_int(sqlite3_stmt, 2, folder_id) != SQLITE_OK)
\r
311 BROWSER_LOGE("sqlite3_bind_int is failed.\n");
\r
312 if (sqlite3_bind_text(sqlite3_stmt, 3, url_to_save.c_str(), -1, NULL) != SQLITE_OK)
\r
313 BROWSER_LOGE("sqlite3_bind_text is failed.\n");
\r
314 if (sqlite3_bind_text(sqlite3_stmt, 4, title_to_save.c_str(), -1, NULL) != SQLITE_OK)
\r
315 BROWSER_LOGE("sqlite3_bind_text is failed.\n");
\r
317 if (get_last_index_result) {
\r
318 if (sqlite3_bind_int(sqlite3_stmt, 5, last_index + 1) != SQLITE_OK)
\r
319 BROWSER_LOGE("sqlite3_bind_int is failed.\n");
\r
322 if (sqlite3_bind_int(sqlite3_stmt, 5, 1) != SQLITE_OK)
\r
323 BROWSER_LOGE("sqlite3_bind_int is failed.\n");
\r
326 error = sqlite3_step(sqlite3_stmt);
\r
328 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
329 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
331 if (_close_db() == EINA_FALSE)
\r
332 BROWSER_LOGE("_close_db is failed.");
\r
334 return (error == SQLITE_DONE);
\r
337 Eina_Bool Browser_Bookmark_DB::is_full(void)
\r
339 unsigned count = 0;
\r
341 if (_open_db() == EINA_FALSE)
\r
344 sqlite3_stmt *sqlite3_stmt = NULL;
\r
345 int error = sqlite3_prepare_v2(m_db_descriptor, "select count(*) from bookmarks", -1, &sqlite3_stmt, NULL);
\r
346 if (error != SQLITE_OK) {
\r
347 BROWSER_LOGD("SQL error=%d", error);
\r
348 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
349 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
354 error = sqlite3_step(sqlite3_stmt);
\r
355 if (error != SQLITE_ROW) {
\r
356 BROWSER_LOGD("SQL error=%d", error);
\r
357 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
358 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
363 count = sqlite3_column_int(sqlite3_stmt, 0);
\r
364 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK) {
\r
365 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
370 if (count >= BROWSER_BOOKMARK_COUNT_LIMIT)
\r
376 Eina_Bool Browser_Bookmark_DB::is_duplicated(int folder_id, const char* title, const char* url)
\r
378 if (_open_db() == EINA_FALSE)
\r
381 sqlite3_stmt *sqlite3_stmt = NULL;
\r
382 int error = sqlite3_prepare_v2(m_db_descriptor, "select id from bookmarks where parent=? and title=?",
\r
383 -1, &sqlite3_stmt, NULL);
\r
384 if (error != SQLITE_OK) {
\r
385 BROWSER_LOGD("SQL error=%d", error);
\r
386 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
387 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
392 if (sqlite3_bind_int(sqlite3_stmt, 1, folder_id) != SQLITE_OK) {
\r
393 BROWSER_LOGE("sqlite3_bind_int is failed.\n");
\r
397 if (sqlite3_bind_text(sqlite3_stmt, 2, title, -1, NULL) != SQLITE_OK) {
\r
398 BROWSER_LOGE("sqlite3_bind_text is failed.\n");
\r
402 error = sqlite3_step(sqlite3_stmt);
\r
404 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
405 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
407 if (_close_db() == EINA_FALSE)
\r
408 BROWSER_LOGE("_close_db is failed.");
\r
410 if (error == SQLITE_ROW)
\r
416 Eina_Bool Browser_Bookmark_DB::is_duplicated(const char *folder_name)
\r
418 if (_open_db() == EINA_FALSE)
\r
421 sqlite3_stmt *sqlite3_stmt = NULL;
\r
422 int error = sqlite3_prepare_v2( m_db_descriptor, "select id from bookmarks where type=1 and parent=1 and title=?",
\r
423 -1, &sqlite3_stmt, NULL);
\r
424 if (error != SQLITE_OK) {
\r
425 BROWSER_LOGD("SQL error=%d", error);
\r
426 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
427 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
433 if (sqlite3_bind_text(sqlite3_stmt, 1, folder_name, -1, NULL) != SQLITE_OK)
\r
434 BROWSER_LOGE("sqlite3_bind_text is failed.\n");
\r
436 error = sqlite3_step(sqlite3_stmt);
\r
438 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
439 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
443 return (error == SQLITE_ROW);
\r
446 std::string Browser_Bookmark_DB::get_folder_name_by_id(const int folder_id)
\r
448 if (_open_db() == EINA_FALSE)
\r
451 sqlite3_stmt *sqlite3_stmt = NULL;
\r
452 std::string folder_name = "";
\r
454 int error = sqlite3_prepare_v2(m_db_descriptor, "select title from bookmarks where type=1 and id=?",
\r
455 -1, &sqlite3_stmt, NULL);
\r
457 if (error != SQLITE_OK) {
\r
458 BROWSER_LOGD("SQL error=%d", error);
\r
459 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
460 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
462 return folder_name;
\r
465 if (sqlite3_bind_int(sqlite3_stmt, 1, folder_id) != SQLITE_OK) {
\r
466 BROWSER_LOGE("sqlite3_bind_int is failed.\n");
\r
467 return folder_name;
\r
470 error = sqlite3_step(sqlite3_stmt);
\r
472 if (error == SQLITE_ROW)
\r
473 folder_name = reinterpret_cast<const char *>(sqlite3_column_text(sqlite3_stmt,0));
\r
475 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
476 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
478 if (_close_db() == EINA_FALSE)
\r
479 BROWSER_LOGE("_close_db is failed.");
\r
481 return folder_name;
\r
484 Eina_Bool Browser_Bookmark_DB::get_folder_id(int current_folder_id, const char *folder_name, int *folder_id)
\r
486 if (folder_name == NULL || strlen(folder_name) <= 0) {
\r
487 BROWSER_LOGE("folder name is invalid.\n");
\r
490 if (_open_db() == EINA_FALSE)
\r
493 sqlite3_stmt *sqlite3_stmt = NULL;
\r
494 int error = sqlite3_prepare_v2(m_db_descriptor, "select id from bookmarks where type=1 and parent=? and title=?",
\r
495 -1, &sqlite3_stmt, NULL);
\r
496 if (error != SQLITE_OK) {
\r
497 BROWSER_LOGD("SQL error=%d", error);
\r
498 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
499 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
506 if (sqlite3_bind_int(sqlite3_stmt, 1, current_folder_id) != SQLITE_OK) {
\r
507 BROWSER_LOGE("sqlite3_bind_int is failed.\n");
\r
510 if (sqlite3_bind_text(sqlite3_stmt, 2, folder_name, -1, NULL) != SQLITE_OK) {
\r
511 BROWSER_LOGE("sqlite3_bind_text is failed.\n");
\r
515 // checking if a bookmark exists
\r
516 error = sqlite3_step(sqlite3_stmt);
\r
518 *folder_id = BROWSER_BOOKMARK_MAIN_FOLDER_ID; //just in case
\r
520 if (error == SQLITE_ROW || error == SQLITE_DONE)
\r
521 *folder_id = sqlite3_column_int(sqlite3_stmt, 0);
\r
523 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
524 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
526 if (_close_db() == EINA_FALSE) {
\r
527 BROWSER_LOGE("_close_db is failed.");
\r
531 return (error == SQLITE_DONE || error == SQLITE_ROW);
\r
534 Eina_Bool Browser_Bookmark_DB::modify_bookmark(int bookmark_id, int folder_id, const char *title, const char *url)
\r
536 BROWSER_LOGD("[%s]", __func__);
\r
538 int last_index = 0;
\r
539 Eina_Bool get_last_index_result = EINA_TRUE;
\r
540 if (!_get_last_index(folder_id, &last_index)) {
\r
541 BROWSER_LOGE("_get_last_index failed.\n");
\r
542 get_last_index_result = EINA_FALSE;
\r
545 if (_open_db() == EINA_FALSE)
\r
548 sqlite3_stmt *sqlite3_stmt = NULL;
\r
549 int error = sqlite3_prepare_v2(m_db_descriptor, "update bookmarks set title=?, address=?, parent=?, updatedate=DATETIME('now'), sequence=? where id=?",
\r
550 -1, &sqlite3_stmt, NULL);
\r
551 if (error != SQLITE_OK) {
\r
552 BROWSER_LOGD("SQL error=%d", error);
\r
553 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
554 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
559 if (sqlite3_bind_text(sqlite3_stmt, 1, title, -1, NULL) != SQLITE_OK)
\r
560 BROWSER_LOGE("sqlite3_bind_text is failed.\n");
\r
561 if (sqlite3_bind_text(sqlite3_stmt, 2, url, -1, NULL) != SQLITE_OK)
\r
562 BROWSER_LOGE("sqlite3_bind_text is failed.\n");
\r
563 if (sqlite3_bind_int(sqlite3_stmt, 3, folder_id) != SQLITE_OK)
\r
564 BROWSER_LOGE("sqlite3_bind_int is failed.\n");
\r
566 if (get_last_index_result) {
\r
567 if (sqlite3_bind_int(sqlite3_stmt, 4, last_index + 1) != SQLITE_OK)
\r
568 BROWSER_LOGE("sqlite3_bind_int is failed.\n");
\r
570 if (sqlite3_bind_int(sqlite3_stmt, 4, 1) != SQLITE_OK)
\r
571 BROWSER_LOGE("sqlite3_bind_int is failed.\n");
\r
574 if (sqlite3_bind_int(sqlite3_stmt, 5, bookmark_id) != SQLITE_OK)
\r
575 BROWSER_LOGE("sqlite3_bind_int is failed.\n");
\r
577 error = sqlite3_step(sqlite3_stmt);
\r
579 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
580 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
584 return (error == SQLITE_DONE);
\r
587 Eina_Bool Browser_Bookmark_DB::modify_bookmark_title(int bookmark_id, const char *title)
\r
589 BROWSER_LOGD("[%s]", __func__);
\r
590 if (_open_db() == EINA_FALSE)
\r
593 sqlite3_stmt *sqlite3_stmt = NULL;
\r
594 int error = sqlite3_prepare_v2(m_db_descriptor, "update bookmarks set title=?, updatedate=DATETIME('now') where id=?",
\r
595 -1, &sqlite3_stmt, NULL);
\r
596 if (error != SQLITE_OK) {
\r
597 BROWSER_LOGD("SQL error=%d", error);
\r
598 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
599 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
603 if (sqlite3_bind_text(sqlite3_stmt, 1, title, -1, NULL) != SQLITE_OK)
\r
604 BROWSER_LOGE("sqlite3_bind_text is failed.\n");
\r
606 if (sqlite3_bind_int(sqlite3_stmt, 2, bookmark_id) != SQLITE_OK)
\r
607 BROWSER_LOGE("sqlite3_bind_int is failed.\n");
\r
609 error = sqlite3_step(sqlite3_stmt);
\r
610 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
611 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
613 if (_close_db() == EINA_FALSE) {
\r
614 BROWSER_LOGE("_close_db is failed.");
\r
618 return (error == SQLITE_DONE);
\r
621 Eina_Bool Browser_Bookmark_DB::modify_bookmark_order_index(int bookmark_id, int folder_id, int order_index)
\r
623 if (_open_db() == EINA_FALSE)
\r
626 sqlite3_stmt *sqlite3_stmt = NULL;
\r
627 int error = sqlite3_prepare_v2(m_db_descriptor, "update bookmarks set sequence=? where parent=? and id=?",
\r
628 -1, &sqlite3_stmt, NULL);
\r
629 if (error != SQLITE_OK) {
\r
630 BROWSER_LOGD("SQL error=%d", error);
\r
631 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
632 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
637 if (sqlite3_bind_int(sqlite3_stmt, 1, order_index) != SQLITE_OK)
\r
638 BROWSER_LOGE("sqlite3_bind_int is failed.\n");
\r
640 if (sqlite3_bind_int(sqlite3_stmt, 2, folder_id) != SQLITE_OK)
\r
641 BROWSER_LOGE("sqlite3_bind_int is failed.\n");
\r
643 if (sqlite3_bind_int(sqlite3_stmt, 3, bookmark_id) != SQLITE_OK)
\r
644 BROWSER_LOGE("sqlite3_bind_int is failed.\n");
\r
646 error = sqlite3_step(sqlite3_stmt);
\r
647 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
648 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
652 return (error == SQLITE_DONE);
\r
655 Eina_Bool Browser_Bookmark_DB::get_untitled_folder_count(int *count)
\r
657 BROWSER_LOGD("[%s]", __func__);
\r
658 if (_open_db() == EINA_FALSE)
\r
661 sqlite3_stmt *sqlite3_stmt = NULL;
\r
662 std::string statement = "select title from bookmarks where type=1 and title like '%Folder_%' order by length(title), title";
\r
663 int error = sqlite3_prepare_v2(m_db_descriptor, statement.c_str(), -1, &sqlite3_stmt, NULL);
\r
664 if (error != SQLITE_OK) {
\r
665 BROWSER_LOGD("SQL error=%d", error);
\r
666 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
667 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
673 std::string title_from_db;
\r
674 char buf[32] = {0, };
\r
675 for (int i = 1; ; i++) {
\r
677 error = sqlite3_step(sqlite3_stmt);
\r
678 if (error == SQLITE_ROW) {
\r
679 snprintf(buf, sizeof(buf)-1, "Folder_%02d", i);
\r
681 title_from_db = reinterpret_cast<const char *>(sqlite3_column_text(sqlite3_stmt,0));
\r
682 if (title_from_db != title)
\r
688 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
689 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
693 return (error == SQLITE_DONE || error == SQLITE_ROW);
\r
696 Browser_Bookmark_DB::bookmark_item *Browser_Bookmark_DB::get_bookmark_item_by_id(int bookmark_id)
\r
698 BROWSER_LOGD("[%s]", __func__);
\r
699 if (_open_db() == EINA_FALSE) {
\r
700 BROWSER_LOGE("open failed");
\r
703 sqlite3_stmt *sqlite3_stmt = NULL;
\r
704 int error = sqlite3_prepare_v2(m_db_descriptor, "select type,parent,address,title,sequence,editable from bookmarks where id=?",
\r
705 -1, &sqlite3_stmt, NULL);
\r
706 if (error != SQLITE_OK) {
\r
707 BROWSER_LOGD("SQL error=%d", error);
\r
708 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
709 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
713 if (sqlite3_bind_int(sqlite3_stmt, 1, bookmark_id) != SQLITE_OK) {
\r
714 BROWSER_LOGE("sqlite3_bind_int is failed.\n");
\r
718 bookmark_item *item = NULL;
\r
719 if ((error = sqlite3_step(sqlite3_stmt)) == SQLITE_ROW) {
\r
720 item = new(nothrow) bookmark_item;
\r
722 BROWSER_LOGE("bookmark_item new is failed.\n");
\r
726 item->id = bookmark_id;
\r
727 if (sqlite3_column_int(sqlite3_stmt, 0) == BOOKMARK_NORMAL)
\r
728 item->is_folder = EINA_FALSE;
\r
730 item->is_folder = EINA_TRUE;
\r
732 if (!item->is_folder) {
\r
733 const char* url = reinterpret_cast<const char *>(sqlite3_column_text(sqlite3_stmt, 2));
\r
734 if (url && strlen(url) > 0)
\r
740 item->parent = sqlite3_column_int(sqlite3_stmt, 1);
\r
742 const char* title = reinterpret_cast<const char *>(sqlite3_column_text(sqlite3_stmt, 3));
\r
743 if (title && strlen(title) > 0)
\r
744 item->title = title;
\r
748 item->order_index = sqlite3_column_int(sqlite3_stmt, 4);
\r
749 item->is_editable = EINA_TRUE;//sqlite3_column_int(sqlite3_stmt, 5);
\r
751 item->is_delete = EINA_FALSE;
\r
752 item->user_data_1 = NULL;
\r
753 item->user_data_2 = NULL;
\r
754 item->user_data_3 = 0;
\r
757 error = sqlite3_finalize(sqlite3_stmt);
\r
758 if (error != SQLITE_OK)
\r
760 BROWSER_LOGE("sqlite3_finalize is failed. (%d)", error);
\r
764 if (_close_db() == EINA_FALSE) {
\r
765 BROWSER_LOGE("_close_db is failed.");
\r
772 Eina_Bool Browser_Bookmark_DB::get_bookmark_list(std::vector<bookmark_item *> &list, int folder_id)
\r
774 BROWSER_LOGD("[%s]", __func__);
\r
775 if (_open_db() == EINA_FALSE) {
\r
776 BROWSER_LOGE("open failed");
\r
780 sqlite3_stmt *sqlite3_stmt = NULL;
\r
781 int error = sqlite3_prepare_v2(m_db_descriptor, "select id,type,parent,address,title,sequence,editable from bookmarks where parent=? order by sequence",
\r
782 -1,&sqlite3_stmt,NULL);
\r
783 if (error != SQLITE_OK) {
\r
784 BROWSER_LOGD("SQL error=%d", error);
\r
785 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
786 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
790 if (sqlite3_bind_int(sqlite3_stmt, 1, folder_id) != SQLITE_OK) {
\r
791 BROWSER_LOGE("sqlite3_bind_int is failed.\n");
\r
795 bookmark_item *item;
\r
796 while ((error = sqlite3_step(sqlite3_stmt)) == SQLITE_ROW) {
\r
797 item = new(nothrow) bookmark_item;
\r
799 BROWSER_LOGE("bookmark_item new is failed.\n");
\r
803 item->id = sqlite3_column_int(sqlite3_stmt, 0);
\r
804 if (sqlite3_column_int(sqlite3_stmt, 1) == BOOKMARK_NORMAL)
\r
805 item->is_folder = EINA_FALSE;
\r
807 item->is_folder = EINA_TRUE;
\r
809 if (!item->is_folder) {
\r
810 const char* url = reinterpret_cast<const char *>(sqlite3_column_text(sqlite3_stmt, 3));
\r
811 if (url && strlen(url) > 0)
\r
817 item->parent = sqlite3_column_int(sqlite3_stmt, 2);
\r
819 const char* title = reinterpret_cast<const char *>(sqlite3_column_text(sqlite3_stmt, 4));
\r
820 if (title && strlen(title) > 0)
\r
821 item->title = title;
\r
825 item->order_index = sqlite3_column_int(sqlite3_stmt, 5);
\r
826 item->is_editable = EINA_TRUE;//sqlite3_column_int(sqlite3_stmt, 6);
\r
828 item->is_delete = EINA_FALSE;
\r
829 item->user_data_1 = NULL;
\r
830 item->user_data_2 = NULL;
\r
831 item->user_data_3 = 0;
\r
832 list.push_back(item);
\r
835 error = sqlite3_finalize(sqlite3_stmt);
\r
836 if (error != SQLITE_OK)
\r
838 BROWSER_LOGE("sqlite3_finalize is failed. (%d)", error);
\r
842 if (_close_db() == EINA_FALSE) {
\r
843 BROWSER_LOGE("_close_db is failed.");
\r
850 Eina_Bool Browser_Bookmark_DB::get_folder_list(std::vector<bookmark_item *> &list)
\r
852 if (_open_db() == EINA_FALSE)
\r
855 sqlite3_stmt *sqlite3_stmt = NULL;
\r
856 int error = sqlite3_prepare_v2(m_db_descriptor, "select id,type,parent,address,title,sequence from bookmarks where type=1 and parent=? order by sequence",
\r
857 -1, &sqlite3_stmt, NULL);
\r
858 if (error != SQLITE_OK) {
\r
859 BROWSER_LOGD("SQL error=%d", error);
\r
860 if (sqlite3_finalize(sqlite3_stmt) != SQLITE_OK)
\r
861 BROWSER_LOGE("sqlite3_finalize is failed.\n");
\r
866 if (sqlite3_bind_int(sqlite3_stmt, 1, BROWSER_BOOKMARK_MAIN_FOLDER_ID) != SQLITE_OK)
\r
867 BROWSER_LOGE("sqlite3_bind_int is failed.\n");
\r
869 bookmark_item *item;
\r
870 while ((error = sqlite3_step(sqlite3_stmt)) == SQLITE_ROW)
\r
872 item = new(nothrow) bookmark_item;
\r
874 BROWSER_LOGE("bookmark_item new is failed.\n");
\r
878 item->id = sqlite3_column_int(sqlite3_stmt, 0);
\r
879 item->is_folder = sqlite3_column_int(sqlite3_stmt, 1) == BOOKMARK_NORMAL ? EINA_FALSE : EINA_TRUE;
\r
880 item->parent = sqlite3_column_int(sqlite3_stmt, 2);
\r
883 const char* title = reinterpret_cast<const char *>(sqlite3_column_text(sqlite3_stmt, 4));
\r
884 if (title && strlen(title)>0)
\r
885 item->title = title;
\r
888 item->order_index = sqlite3_column_int(sqlite3_stmt, 5);
\r
889 item->is_editable = EINA_TRUE;
\r
890 item->is_delete = EINA_FALSE;
\r
892 list.push_back(item);
\r
895 error = sqlite3_finalize(sqlite3_stmt);
\r
896 if (error != SQLITE_OK)
\r
897 BROWSER_LOGE("sqlite3_finalize is failed. (%d)\n", error);
\r
901 return (error == SQLITE_DONE || error == SQLITE_OK);
\r