Skip to content

Commit 1589554

Browse files
committed
Finished datatypes
1 parent fae97e1 commit 1589554

4 files changed

Lines changed: 39 additions & 33 deletions

File tree

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[![jSQL Logo](http://i.imgur.com/VQlJKOc.png)](http://pamblam.github.io/jSQL/)
22

3-
jSQL (Official) - Version 2.9 - *Now gluten free!*
3+
jSQL (Official) - Version 2.9.1 - *Now gluten free!*
4+
45
[![npm version](https://badge.fury.io/js/jsql-official.svg)](https://badge.fury.io/js/jsql-official) [![Build Status](https://travis-ci.org/Pamblam/jSQL.svg?branch=master)](https://travis-ci.org/Pamblam/jSQL) [![Inline docs](http://inch-ci.org/github/Pamblam/jSQL.svg?branch=master)](http://inch-ci.org/github/Pamblam/jSQL)
56

67
<hr>
@@ -80,16 +81,18 @@ jSQL is fully documented in the [jSQL Wiki](https://github.com/Pamblam/jSQL/wiki
8081

8182
## Browser Support
8283

83-
Works in all major browsers, even really old ones.
84+
Works in basically all browsers. jSQL degrades gracefully because it falls back on cookies for persistence if localStorage, IndexedDB and WebSQL are not available. To that end, the library itself does not take advantage of any ES6 features, if you want something that does, have a look at [alaSQL](https://github.com/agershun/alasql).
85+
86+
While jSQL will work in basically all browsers, these ones are preferred:
8487

8588
| **FireFox** | **Android** | **Safari** | **Chrome** | **Samsung** | **Blackberry** | **IE** | **Opera** | **Edge** |
8689
|-------------|-------------|------------|------------|-------------|----------------|--------|-----------|----------|
8790
| 2+ | 2.1+ | 3.1+ | 4+ | 4+ | 7+ | 8+ | 11.5+ | 12+ |
8891

8992
<hr>
9093

91-
## License & Legal
94+
## It's Official
9295

93-
License info is available [here](https://github.com/Pamblam/jSQL/wiki/License).
96+
In the same way Fedex is Federal.
9497

9598
<hr>

jSQL.js

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@
8888
case "0065": this.message = "AUTO_INCREMENT column must be a key."; break;
8989
case "0066": this.message = "AUTO_INCREMENT column must be an INT type."; break;
9090
case "0067": this.message = "API is out of memory, cannot store more data."; break;
91+
case "0068": this.message = "Invalid ENUM value."; break;
92+
case "0069": this.message = "NUMERIC or INT type invalid or out of range."; break;
9193
default: this.message = "Unknown error."; break;
9294
}
9395
this.toString = function () {
@@ -117,23 +119,25 @@
117119
aliases: ["NUMBER", "DECIMAL", "FLOAT"],
118120
serialize: function(value, args){
119121
return !isNaN(parseFloat(value)) && isFinite(value) ?
120-
parseFloat(value) : 0;
122+
parseFloat(value) :
123+
_throw(new jSQL_Error("0069")) ;
121124
},
122125
unserialize: function(value, args){
123126
return !isNaN(parseFloat(value)) && isFinite(value) ?
124-
parseFloat(value) : 0;
127+
parseFloat(value) :
128+
_throw(new jSQL_Error("0069")) ;
125129
}
126130
},{
127131
type: "ENUM",
128-
serialize: function(value, args){ return "tits";
132+
serialize: function(value, args){
129133
for(var i=args.length; i--;)
130-
if(value == removeQuotes(args[i])) return removeQuotes(args[i]);
131-
return removeQuotes(args[0]);
134+
if(value.toUpperCase() == removeQuotes(args[i]).toUpperCase()) return removeQuotes(args[i]);
135+
return _throw(new jSQL_Error("0068"));
132136
},
133-
unserialize: function(value, args){ return "tits";
137+
unserialize: function(value, args){
134138
for(var i=args.length; i--;)
135-
if(value == removeQuotes(args[i])) return removeQuotes(args[i]);
136-
return removeQuotes(args[0]);
139+
if(value.toUpperCase() == removeQuotes(args[i]).toUpperCase()) return removeQuotes(args[i]);
140+
return _throw(new jSQL_Error("0068"));
137141
}
138142
},{
139143
type: "TINYINT",
@@ -151,44 +155,48 @@
151155
serialize: function(value, args){
152156
return !isNaN(parseInt(value)) && isFinite(value) &&
153157
value >= -32768 && value <= 32767 ?
154-
parseInt(value) : 0;
158+
parseInt(value) :
159+
_throw(new jSQL_Error("0069")) ;
155160
},
156161
unserialize: function(value, args){
157162
return !isNaN(parseInt(value)) && isFinite(value) ?
158-
parseInt(value) : 0;
163+
parseInt(value) :
164+
_throw(new jSQL_Error("0069")) ;
159165
}
160166
},{
161167
type: "MEDIUMINT",
162168
serialize: function(value, args){
163169
return !isNaN(parseInt(value)) && isFinite(value) &&
164170
value >= -8388608 && value <= 8388607 ?
165-
parseInt(value) : 0;
171+
parseInt(value) :
172+
_throw(new jSQL_Error("0069")) ;
166173
},
167174
unserialize: function(value, args){
168175
return !isNaN(parseInt(value)) && isFinite(value) ?
169-
parseInt(value) : 0;
176+
parseInt(value) :
177+
_throw(new jSQL_Error("0069")) ;
170178
}
171179
},{
172180
type: "INT",
173181
serialize: function(value, args){
174182
return !isNaN(parseInt(value)) && isFinite(value) &&
175183
value >= -2147483648 && value <= 2147483647 ?
176-
parseInt(value) : 0;
184+
parseInt(value) : _throw(new jSQL_Error("0069"));
177185
},
178186
unserialize: function(value, args){
179187
return !isNaN(parseInt(value)) && isFinite(value) ?
180-
parseInt(value) : 0;
188+
parseInt(value) : _throw(new jSQL_Error("0069"));
181189
}
182190
},{
183191
type: "BIGINT",
184192
serialize: function(value, args){
185193
return !isNaN(parseInt(value)) && isFinite(value) &&
186194
value >= -9007199254740991 && value <= 9007199254740991 ?
187-
parseInt(value) : 0;
195+
parseInt(value) : _throw(new jSQL_Error("0069"));
188196
},
189197
unserialize: function(value, args){
190198
return !isNaN(parseInt(value)) && isFinite(value) ?
191-
parseInt(value) : 0;
199+
parseInt(value) : _throw(new jSQL_Error("0069"));
192200
}
193201
},{
194202
type: "JSON",
@@ -581,7 +589,6 @@
581589
var storeVal = jSQL.types.getByType(type.type.toUpperCase()).serialize(value, type.args);
582590
if((!isNaN(parseFloat(storeVal)) && isFinite(storeVal)) || typeof storeVal === "string")
583591
return storeVal;
584-
console.log(storeVal);
585592
return _throw(new jSQL_Error("0020"));
586593
};
587594

@@ -753,7 +760,6 @@
753760
this.data[i] = preparedVals.shift();
754761
}
755762
}
756-
console.log(this.data);
757763
jSQL.tables[this.table].insertRow(this.data, this.ignoreFlag);
758764
return this;
759765
};
@@ -2561,7 +2567,6 @@
25612567
self.api.init([{name: "jSQL_data_schema", rows:[]}], successCallback);
25622568
APIIsSet = true;
25632569
}catch(ex){
2564-
console.log(ex);
25652570
APIIsSet = false;
25662571
}
25672572
if(!APIIsSet) loop(1+i);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"example": "tests"
88
},
99
"scripts": {
10-
"test": "node ./tests/test1.js && node ./tests/test2.js && node ./tests/test3.js && node ./tests/test4.js && node ./tests/test5.js"
10+
"test": "node ./tests/test1.js && node ./tests/test2.js && node ./tests/test3.js && node ./tests/test4.js && node ./tests/test5.js && node ./tests/test6.js"
1111
},
1212
"repository": {
1313
"type": "git",

tests/test6.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
var jSQL = require("../jSQL.js");
77

88
jSQL.load(function(){
9-
9+
1010
jSQL.query("create table typetest ("+
1111
"id numeric(3), "+
1212
"data json, "+
@@ -17,15 +17,13 @@ jSQL.load(function(){
1717
"name varchar(4), "+
1818
"created date, "+
1919
"anything ambi, "+
20-
"something enum('poop','pee')"+
20+
"something enum('hello','goodbye')"+
2121
" )").execute();
22-
22+
2323
var sql = "insert into typetest values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
24-
params = [2.1, {"3":3}, function(){alert("hello")}, true, 4, 'y12', 'bob', new Date(), 'poooo', 'pee'];
24+
params = [2.1, {"3":3}, function(){}, true, 4, 'y12', 'bob', new Date(), 'something', 'hello'];
2525
jSQL.query(sql).execute(params);
26-
27-
// var data = jSQL.query("select * from typetest").execute().fetch();
28-
// console.log(data);
29-
// data.greet()
30-
26+
27+
var data = jSQL.query("select * from typetest").execute().fetch();
28+
console.log("done 6");
3129
});

0 commit comments

Comments
 (0)