-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSavedDatas.as
More file actions
149 lines (125 loc) · 3.55 KB
/
SavedDatas.as
File metadata and controls
149 lines (125 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package dataManager
{
import flash.data.SQLConnection;
import flash.data.SQLMode;
import flash.data.SQLResult;
import flash.data.SQLStatement;
import flash.events.SQLErrorEvent;
import flash.events.SQLEvent;
import flash.filesystem.File;
import flash.utils.ByteArray;
public class SavedDatas
{
private static var sql:SQLConnection ,
query:SQLStatement;
private static var dbFolder:String = "DB",
dbName:String = "saves",
tableName:String = "SAVED_DATA",
field_id:String = "ID",
field_value:String = "VALUE";
private static var unicCode:String = 'deviceUnicCode';
private static var systemCode:String ;
private static var temporaryObject:Object ;
/**get the device unic code if there is or set a new one on it*/
public static function setOrGetDeviceCode():String
{
return '18888485mteamapps.com156848514' ;
}
public static function setUp()
{
if(sql == null)
{
temporaryObject = {};
var sqlFile:File = File.applicationStorageDirectory.resolvePath(dbFolder);
if(!sqlFile.exists)
{
sqlFile.createDirectory() ;
}
sqlFile = sqlFile.resolvePath(dbName);
var encrypt:ByteArray = new ByteArray();
encrypt.writeUTFBytes(setOrGetDeviceCode().substring(0,16));
sql = new SQLConnection();
sql.open(sqlFile,"create",false,1024,encrypt);
query = new SQLStatement();
query.sqlConnection = sql ;
try
{
query.text = "create table "+tableName+" ("+field_id+" VARCHAR(1) , "+field_value+" VARCHAR(1))";
query.execute();
trace('table is creats');
}
catch(e)
{
trace('table was created');
}
}
}
/**save stringifi value for this id on data base*/
public static function save(id:String,data:String):void
{
setUp();
//trace("save this data : "+data);
//hint : if data is nul , it will cause to skip this function ,at the bigining of the app job , all temporaryObject variables are null
if(data!= null && temporaryObject[id] == data)
{
//trace("temporaryObject[id] is : "+temporaryObject[id]);
return ;
}
//trace("save this data2 : "+temporaryObject[id]);
temporaryObject[id] = data ;
sql.begin();
query.text = "delete from "+tableName+" where "+field_id+" == '"+id+"'" ;
try
{
query.execute();
}
catch(e){}
query.text = "insert into "+tableName+" ( "+field_id+" , "+field_value+" ) values( '"+id+"' , '"+data+"' )";
try
{
query.execute();
sql.commit();
//trace(data+" saved");
}
catch(e)
{
sql.rollback();
}
}
/**load the value with this id if it saved befor<br>
* if no value founds , it will return null instead of some Stringifi data*/
public static function load(id:String):*
{
setUp();
var check:String = temporaryObject[id];
if(check!=null)
{
return check;
}
//trace("it have to send query to db to detect the data");
query.text = "select "+field_value+" from "+tableName+" where "+field_id+" == '"+id+"'";
try
{
query.execute();
var result:SQLResult = query.getResult() ;
if(result.data == null)
{
return null ;
}
else
{
//trace('result on query is : '+(result.data[0][field_value]==null)+' > check string : '+(result.data[0][field_value]=='null'));
var res:String = result.data[0][field_value] ;
if(res == 'null')
{
res = null ;
}
return res ;
}
}
catch(e){}
return null ;
}
////////////////////////////////debug function for section id and mac id↓
}
}