如何访问外部创建的sqlite数据库 [英] How to access the sqlite db which is externally created
问题描述
我正在使用visual studio中的telerik app builder创建一个混合应用程序。我无法访问外部创建的sqlite db。但我可以访问在运行时创建的数据库。我提到了一些网站,这些解决方案并不适合我。以下代码将创建db并在运行时访问它
var app = {};
app.db = null ;
app.openDb = function (){
var dbName =& quot; Test.sqlite& quot ;;
// 模拟器的数据库创建
if ( window 。 navigator .simulator === true ){
app.db = window .openDatabase(dbName,& quot; 1 .0& quot;,& quot; Test Database& quot;, 1073741824 );
console .log(& quot; Database Created!& quot;);
}
// 设备数据库创建
else {
app.db = window .sqlitePlugin.openDatabase(dbName);
console .log(& quot; Database Accessed!& quot;);
}
}
我想访问〜/ data / Test中存在的数据库。 sqlite文件夹。
我在我的页面中包含以下脚本
< script src =js /AosJS/common.js\"></script>
< script src =js / vendor / jquery-2.1.0.min.js>< / script>
< script src =js / angular.min.js>< / script>
< script src =js / AosJS / index.js >< / script>
< script src =js / ng-cordova.min.js>< / script>
我尝试了什么:
我试图将数据库放在www文件夹中并尝试通过以下代码访问它
app.db = window .sqlitePlugin.openDatabase({name : Test.db,createFromLocation: 1 });
它会出现以下错误
未捕获的TypeError:无法读取未定义的属性'openDatabase'
其实我错过了对cordova的js参考
你是是的,实际上我错过了包含以下cordova脚本< script type =" text / javascript"字符集=" UTF-8英寸SRC =" cordova.js">< /脚本>
I am creating a hybrid app by telerik app builder in visual studio. I am not able to access sqlite db which is created externally. But I can access the db which is created at run time. I referred some sites, those solutions are not worked for me. The following code will create db and access it while run time
var app = {};
app.db = null;
app.openDb = function () {
var dbName = "Test.sqlite";
//DB creation for Simulator
if (window.navigator.simulator === true) {
app.db = window.openDatabase(dbName, "1.0", "Test Database", 1073741824);
console.log("Database Created!");
}
//DB creation for devices
else {
app.db = window.sqlitePlugin.openDatabase(dbName);
console.log("Database Accessed!");
}
}
I want to access the database which is present in the ~/data/Test.sqlite folder.
I Included the following scripts in my page
<script src="js/AosJS/common.js"></script>
<script src="js/vendor/jquery-2.1.0.min.js"></script>
<script src="js/angular.min.js"></script>
<script src="js/AosJS/index.js"></script>
<script src="js/ng-cordova.min.js"></script>
What I have tried:
I tried to place the db in www folder and try to access it by the following code
app.db = window.sqlitePlugin.openDatabase({name: "Test.db", createFromLocation: 1});
It will give the following error
Uncaught TypeError: Cannot read property 'openDatabase' of undefined
Actually I missed the js reference for cordova
You are correct, actually I missed to include the following cordova script <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
这篇关于如何访问外部创建的sqlite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!