[[pagelist(html5)]] [[tableofcontents]] = 개요 = * SeeAlso) [html5/web-storage] * 로컬 ì €ìž¥ì†Œì˜ ì¼ë¶€. [html5/web-storage]ì™¸ì— ì¶”ê°€ ì œê³µë˜ëŠ” 것. * 브ë¼ìš°ì € ìžì²´ 경량 DB * web storage와 ë¹„êµ * WebStorage는 간단한 ë°ì´í„°ë¥¼ ì €ìž¥í•˜ê¸° ì í•©. * WebSqlDatabase는 보다 구조ì ì´ê³ ì²´ê³„í™”ëœ ê´€ê³„í˜• ë°ì´í„° ë² ì´ìŠ¤ë¥¼ 대량으로 ì €ìž¥ * ì•ˆì •ì ì¸ ê²½ëŸ‰ 관계형 ìžë£Œêµ¬ì¡° 지ì›, 표준 SQLì§ˆì˜ ì§€ì› *SQLite를 기반으로 í•˜ê³ ìžˆë‹¤. == 브ë¼ìš°ì € ì§€ì› == * ì˜ì™¸ë¡œ 파ì´ì–´í스ì—ì„œ 지ì›í•˜ì§€ 않는다. * '''심지어 내부 디비가 sqlite ìž„ì—ë„ ë¶ˆêµ¬í•˜ê³ .''' * ì•„ëž˜ì˜ ì½”ë“œë¥¼ ì´ìš©í•˜ë©´ ì§€ì› ì—¬ë¶€ë¥¼ í™•ì¸ í• ìˆ˜ 있다. {{{ if(!!window.openDatabase) { alert("현재 브ë¼ìš°ì €ëŠ” Web SQL Database를 지ì›í•©ë‹ˆë‹¤") } else{ alert("현재 브ë¼ìš°ì €ëŠ” Web SQL Database를 지ì›í•˜ì§€ 않습니다") } }}} == Indexed Database == * SeeAlso) [html5/indexedDatabase] * Indexed Database는 새로 등장한 ë˜ë‹¤ë¥¸ 로컬 ì €ìž¥ì†Œ 스펙ì´ë‹¤ * 2009ë…„ ë§ê¹Œì§€ 사양 ì±…ì •ì´ ì§„í–‰ì¤‘ì´ë˜ Web SQL Database ì˜ ëŒ€ì•ˆìœ¼ë¡œ 탄ìƒí–ˆë‹¤ * 현재 Web SQL Database 는 사양 ì±…ì •ì´ ì¤‘ì§€ëœ ìƒíƒœì´ë©°, IndexedDB ë¼ëŠ” 새로운 ìŠ¤íŽ™ì´ ëŒ€ì•ˆìœ¼ë¡œ ë– ì˜¤ë¥´ê³ ìžˆë‹¤ = 특징 = * 비ë™ê¸° ìž‘ì—… ì´ë¯€ë¡œ UIì— ìµœì†Œí•œì˜ ì˜í–¥ì„ 준다. * ë„ë©”ì¸ ë‹¨ìœ„ë¡œ DBê°€ 분리ëœë‹¤. * íŠ¹ì • ë„ë©”ì¸ì—ì„œ ìƒì„±ëœ 디비는 다른 ë„ë©”ì¸ì—ì„œ ì ‘ê·¼í• ìˆ˜ 없다. * ì¼ë°˜ì ì¸ DB 사용법과 비슷하다. ì—´ê³ , ìˆ˜í–‰í•˜ê³ , ë‹«ê³ . = 사용법 = * 비ë™ê¸° ì‹ì´ë‹¤. * transactionì„ ì§€ì›í•œë‹¤. * {{{transaction()}}}, {{{readTransaction}}} == 변수 ì„ ì–¸ == {{{ var html5rocks = {}; html5rocks.webdb = {}; }}} == 열기 == * ì‚¬ìš©ì „ì— ë°˜ë“œì‹œ ë°ì´í„° ë² ì´ìŠ¤ë¥¼ 열어야 한다. {{{ html5rocks.webdb.db = null; html5rocks.webdb.open = function() { var dbSize = 5 * 1024 * 1024; // 5MB html5rocks.webdb.db = openDatabase('Todo', '1.0', 'todo manager', dbSize); } html5rocks.webdb.onError = function(tx, e) { alert('Something unexpected happened: ' + e.message ); } html5rocks.webdb.onSuccess = function(tx, r) { // re-render all the data html5rocks.webdb.getAllTodoItems(tx, r); } }}} == í…Œì´ë¸” ìƒì„± == * {{{todo table. ID, todo, added_on}}} {{{ html5rocks.webdb.createTable = function() { html5rocks.webdb.db.transaction(function(tx) { tx.executeSql('CREATE TABLE IF NOT EXISTS ' + 'todo(ID INTEGER PRIMARY KEY ASC, todo TEXT, added_on DATETIME)', []); }); } }}} == í…Œì´ë¸”ì— ë°ì´í„° 추가 == * dynamic sql {{{ html5rocks.webdb.addTodo = function(todoText) { html5rocks.webdb.db.transaction(function(tx){ var addedOn = new Date(); tx.executeSql('INSERT INTO todo(todo, added_on) VALUES (?,?)', [todoText, addedOn], html5rocks.webdb.onSuccess, html5rocks.webdb.onError); }); } }}} == 검색 ì§ˆì˜ == * {{{ html5rocks.webdb.getAllTodoItems = function(renderFunc) { html5rocks.webdb.db.transaction(function(tx) { tx.executeSql('SELECT * FROM todo', [], renderFunc, html5rocks.webdb.onError); }); } }}} === ê²°ê³¼ 표시 === {{{ function loadTodoItems(tx, rs) { var rowOutput = ""; for (var i=0; i < rs.rows.length; i++) { rowOutput += renderTodo(rs.rows.item(i)); } var todoItems = document.getElementById('todoItems'); todoItems.innerHTML = rowOutput; } function renderTodo(row) { return '<li>' + row.ID + '[<a onclick="html5rocks.webdb.deleteTodo(' + row.ID + ');"'>X</a>]</li>'; } }}} == ë°ì´í„° 지우기 == {{{ html5rocks.webdb.deleteTodo = function(id) { html5rocks.webdb.db.transaction(function(tx) { tx.executeSql('DELETE FROM todo WHERE ID=?', [id], loadTodoItems, html5rocks.webdb.onError); }); } }}} == hooking it all up == === init === {{{ function init() { html5rocks.webdb.open(); html5rocks.webdb.createTable(); html5rocks.webdb.getAllTodoItems(loadTodoItems); } </script> <body onload="init();"> }}} === adding === {{{ function addTodo() { var todo = document.getElementById('todo'); html5rocks.webdb.addTodo(todo.value); todo.value = ''; } }}} == transaction == {{{ var db = openDatabase('mydb', '1.0', 'my first database', 2 * 1024 * 1024); db.transaction(function (tx) { tx.executeSql('CREATE TABLE IF NOT EXISTS foo (id unique, text)'); tx.executeSql('INSERT INTO foo (id, text) VALUES (1, "synergies")'); }); }}} = ì°¸ê³ = * http://m.mkexdev.net/61 * http://www.html5rocks.com/tutorials/webdatabase/todo/ * http://html5doctor.com/introducing-web-sql-databases/ * http://dev.w3.org/html5/webdatabase/ * http://html5.jidolstar.com/tag/web%20sql%20databaseo