1
Programming / Getting my Head Around Dark Data
« Last post by BrynP on February 29, 2012, 02:42:52 am »Figured I'd put my notes in here as I'm trying to understand it. Unfortunately the help files and examples aren't exactly clear on how it works.
The first thing for DD to do is save the 'database' because that's what it is.
'DFS' is the database and 'KFS' are the keys within the database used for pulling out data.
So to code the database into a saved file.:
Create the file:
DFS Create 1, "Save.dat", 0
The '0' at the end is to decide whether or not it's encrypted.
Then in this database you need to add each database field, so the types of variables:
DFS Add Field 1, "string 1 as num"
DFS Add Field 1, "string 10 as name"
DFS Add Field 1, "integer as level"
DFS Add Field 1, "string 10 as skill"
Then you create the 'keys' for finding each instance of this data.
KFS Create 2, "CheckNum.kfs", 1, 0, 0 `0 - unique
kfs create 3, "CheckName.kfs", 10, 1, 0 `1 - non unique
kfs create 4, "CheckSkill.kfs", 10, 1, 0
Then you can create each instance of data in the data base.
number$ = "1"
name$ = "Keats"
level = 17
skill$ = "Murder"
And record it:
record = DFS Add(1)
DFS Put 1, "num", number$
DFS Put 1, "name", name$
DFS Put 1, "level", str$(level)
DFS Put 1, "skill", skill$
DFS Save 1, record
KFS Add 2, number$, record
kfs add 3, name$, record
KFS Add 4, skill$, record
Then close the database and all keys:
DFS Close 1
KFS Close 2
KFS Close 3
KFS Close 4
Then you can load this data if you wish:
Open the database and all of the keys:
kfs open 2, "CheckNum.kfs"
kfs open 3, "CheckName.kfs"
KFS Open 4, "CheckSkill.kfs"
Then very simply, load the first instance of data
record = 1
dfs load 1,record
number$ = dfs get$(1,"num")
name$ = dfs get$(1,"name")
level = dfs get(1, "level")
skill$ = dfs get$(1, "skill")
You could use a for/next statement to get ALL instances, like:
for x = 1 to KFS Count(2)
record = KFS Next(2)
[insert 'get' code]
next x
Don't forget to close all of the indexes (KFS/DFS)
And you can then make use of those variables.
The first thing for DD to do is save the 'database' because that's what it is.
'DFS' is the database and 'KFS' are the keys within the database used for pulling out data.
So to code the database into a saved file.:
Create the file:
DFS Create 1, "Save.dat", 0
The '0' at the end is to decide whether or not it's encrypted.
Then in this database you need to add each database field, so the types of variables:
DFS Add Field 1, "string 1 as num"
DFS Add Field 1, "string 10 as name"
DFS Add Field 1, "integer as level"
DFS Add Field 1, "string 10 as skill"
Then you create the 'keys' for finding each instance of this data.
KFS Create 2, "CheckNum.kfs", 1, 0, 0 `0 - unique
kfs create 3, "CheckName.kfs", 10, 1, 0 `1 - non unique
kfs create 4, "CheckSkill.kfs", 10, 1, 0
Then you can create each instance of data in the data base.
number$ = "1"
name$ = "Keats"
level = 17
skill$ = "Murder"
And record it:
record = DFS Add(1)
DFS Put 1, "num", number$
DFS Put 1, "name", name$
DFS Put 1, "level", str$(level)
DFS Put 1, "skill", skill$
DFS Save 1, record
KFS Add 2, number$, record
kfs add 3, name$, record
KFS Add 4, skill$, record
Then close the database and all keys:
DFS Close 1
KFS Close 2
KFS Close 3
KFS Close 4
Then you can load this data if you wish:
Open the database and all of the keys:
kfs open 2, "CheckNum.kfs"
kfs open 3, "CheckName.kfs"
KFS Open 4, "CheckSkill.kfs"
Then very simply, load the first instance of data
record = 1
dfs load 1,record
number$ = dfs get$(1,"num")
name$ = dfs get$(1,"name")
level = dfs get(1, "level")
skill$ = dfs get$(1, "skill")
You could use a for/next statement to get ALL instances, like:
for x = 1 to KFS Count(2)
record = KFS Next(2)
[insert 'get' code]
next x
Don't forget to close all of the indexes (KFS/DFS)
And you can then make use of those variables.