-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Insert Query optimized, out of stack error solved
- Loading branch information
1 parent
f81c020
commit c2d2219
Showing
6 changed files
with
223 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
module JsStore { | ||
export module Business { | ||
export class InsertHelper extends Base { | ||
ValuesAffected = []; | ||
Query: IInsert; | ||
|
||
public onTransactionCompleted = function () { | ||
this.OnSuccess(this.Query.Return ? this.ValuesAffected : this.RowAffected); | ||
} | ||
|
||
protected checkModifyInsertValues = function (table, values) { | ||
var That = this, | ||
ValueIndex = 0, | ||
Value, | ||
TableName = table.Name, | ||
checkDatas = function () { | ||
Value = values[ValueIndex++]; | ||
checkInternal(); | ||
}, | ||
checkInternal = function () { | ||
if (Value) { | ||
checkAndModifyValue(); | ||
} | ||
else { | ||
That.insertData(values); | ||
} | ||
}, | ||
checkAndModifyValue = function () { | ||
var Index = 0, | ||
checkAndModifyColumn = function (column) { | ||
if (column) { | ||
var onValidationError = function (error: ErrorType, details: any) { | ||
That.ErrorOccured = true; | ||
That.Error = Utils.getError(error, details); | ||
}, | ||
CheckNotNullAndDataType = function () { | ||
//check not null schema | ||
if (column.NotNull && isNull(Value[column.Name])) { | ||
onValidationError(ErrorType.NullValue, { ColumnName: column.Name }); | ||
} | ||
//check datatype | ||
else if (column.DataType && typeof Value[column.Name] != column.DataType) { | ||
onValidationError(ErrorType.BadDataType, { ColumnName: column.Name }); | ||
} | ||
checkAndModifyColumn(table.Columns[Index++]); | ||
}; | ||
if (!That.ErrorOccured) { | ||
//check auto increment scheme | ||
if (column.AutoIncrement) { | ||
KeyStore.get("JsStore_" + ActiveDataBase.Name + "_" + TableName + "_" + column.Name + "_Value", function (columnValue: number) { | ||
Value[column.Name] = ++columnValue; | ||
KeyStore.set("JsStore_" + ActiveDataBase.Name + "_" + TableName + "_" + column.Name + "_Value", columnValue); | ||
CheckNotNullAndDataType(); | ||
}); | ||
} | ||
else if (column.Default && Value[column.Name] == null) { //check Default Schema | ||
Value[column.Name] = column.Default; | ||
CheckNotNullAndDataType(); | ||
} | ||
else { | ||
CheckNotNullAndDataType(); | ||
} | ||
} | ||
else { | ||
That.onErrorOccured(That.Error, true); | ||
} | ||
} | ||
else { | ||
checkDatas(); | ||
} | ||
} | ||
checkAndModifyColumn(table.Columns[Index++]); | ||
} | ||
checkDatas(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.