Невозможно получить доступ к внешней базе данных SQL из виджета, однако можно прочитать локальный текстовый файл из виджета. Следующий простой пример работает на настольном компьютере с последней установленной версией Opera (11.52).
config.xml:
<?xml version="1.0" encoding="utf-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" id="http://example.com/filereadertest" defaultlocale="en" width="400" height="500">
<name>File Reader Test</name>
<description>File Reader test widget</description>
<author href="http://example.com/author/">Me</author>
<feature name="http://xmlns.opera.com/fileio">
<param name="folderhint" value="home" />
</feature>
</widget>
index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<style>
body {
background:#eee;
}
#output {
width:98%;
height:200px;
}
</style>
</head>
<body>
<div>
<p>Get the contents of a text file</p>
<p><textarea id="output"></textarea></p>
<p><button id="open">Open</button></p>
</div>
<script>
window.addEventListener('DOMContentLoaded', function() {
function openFile(evt) {
opera.io.filesystem.browseForFile("test", "", openFileCallback)
}
function openFileCallback(file) {
if (file) {
fstream = file.open(file, "r");
var output = document.getElementById("output");
output.value = "";
while (!fstream.eof) {
output.value += fstream.readLine("UTF-8");
}
}
}
document.getElementById("open").addEventListener("click", openFile, false);
}, false);
</script>
</body>
</html>
Больше документации здесь:
API ввода-вывода для файла виджета