Skip to content

Commit

Permalink
Fix of the original select from localstorage view problem.
Browse files Browse the repository at this point in the history
  • Loading branch information
positively4th committed Mar 29, 2016
1 parent fefa859 commit 8f36496
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
26 changes: 14 additions & 12 deletions src/420from.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

yy.Select.prototype.compileFrom = function(query) {
// console.log(1);
// console.log(1);
var self = this;
query.sources = [];
// var tableid = this.from[0].tableid;
Expand Down Expand Up @@ -59,29 +59,31 @@ yy.Select.prototype.compileFrom = function(query) {
// columns: []
};

if(tq instanceof yy.Table) {
// Get columns from table
if(tq instanceof yy.Table) {
// Get columns from table
source.columns = alasql.databases[source.databaseid].tables[source.tableid].columns;
// console.log('test',alasql.options.autocommit);
// console.log(997,alasql.databases[source.databaseid].engineid);
// console.log(0,source.databaseid);
// console.log(1,alasql.databases[source.databaseid]);
// console.log(2,alasql.databases[source.databaseid].tables[source.tableid].view);
if(alasql.options.autocommit && alasql.databases[source.databaseid].engineid) {
if(alasql.options.autocommit && alasql.databases[source.databaseid].engineid &&
!alasql.databases[source.databaseid].tables[source.tableid].view
) {
// console.log(997,alasql.databases[source.databaseid].engineid);
// TODO -- make view for external engine
source.datafn = function(query,params,cb,idx, alasql) {
source.datafn = function(query,params,cb,idx, alasql) {
return alasql.engines[alasql.databases[source.databaseid].engineid].fromTable(
source.databaseid, source.tableid,cb,idx,query);
}
} else if(alasql.databases[source.databaseid].tables[source.tableid].view){
source.datafn = function(query,params,cb,idx, alasql) {
var res = alasql.databases[source.databaseid].tables[source.tableid].select(params);
if(cb) res = cb(res,idx,query);
return res;
}
} else if(alasql.databases[source.databaseid].tables[source.tableid].view){
source.datafn = function(query,params,cb,idx, alasql) {
var res = alasql.databases[source.databaseid].tables[source.tableid].select(params);
if(cb) res = cb(res,idx,query);
return res;
}
} else {
// console.log('here');
// console.log('here');
// console.log(420,72,alasql.databases[source.databaseid].tables[source.tableid]);
source.datafn = function(query,params,cb,idx, alasql) {
/*
Expand Down
28 changes: 16 additions & 12 deletions src/60createtable.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ yy.CreateTable.prototype.toString = function() {
} else{
s += ' '+(this.class?'CLASS':'TABLE');
}

if(this.ifnotexists){
s += ' IF NOT EXISTS';
}
Expand Down Expand Up @@ -73,7 +72,7 @@ yy.CreateTable.prototype.toString = function() {
// CREATE TABLE
//yy.CreateTable.prototype.compile = returnUndefined;
yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
// var self = this;
// var self = this;
var db = alasql.databases[this.table.databaseid || databaseid];

var tableid = this.table.tableid;
Expand Down Expand Up @@ -102,7 +101,6 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
}

var table = db.tables[tableid] = new alasql.Table(); // TODO Can use special object?

// If this is a class
if(this.class) {
table.isclass = true;
Expand Down Expand Up @@ -284,7 +282,16 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {
});
}

// console.log(100,db.engineid);

//Used in 420from queryfn when table.view = true!
if(this.view && this.select) {
table.view = true;
// console.log(this.select.toString());
// console.log('this.table.databaseid',this.table.databaseid);
// console.log(this.select.compile(this.table.databaseid||databaseid));
table.select = this.select.compile(this.table.databaseid||databaseid);
}

if(db.engineid) {
// console.log(101,db.engineid);
return alasql.engines[db.engineid].createTable(this.table.databaseid || databaseid, tableid, this.ifnotexists, cb);
Expand All @@ -294,7 +301,9 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {

// }
// if(table.pk) {
table.insert = function(r,orreplace) {


table.insert = function(r,orreplace) {
var oldinserted = alasql.inserted;
alasql.inserted = [r];

Expand Down Expand Up @@ -637,13 +646,8 @@ yy.CreateTable.prototype.execute = function (databaseid, params, cb) {

};

if(this.view && this.select) {
table.view = true;
// console.log(this.select.toString());
// console.log('this.table.databaseid',this.table.databaseid);
// console.log(this.select.compile(this.table.databaseid||databaseid));
table.select = this.select.compile(this.table.databaseid||databaseid);
}


// console.log(databaseid);
// console.log(db.databaseid,db.tables);
// console.log(table);
Expand Down

0 comments on commit 8f36496

Please sign in to comment.