Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
d13076d2
Commit
d13076d2
authored
Dec 11, 2007
by
Bradley C. Kuszmaul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify further. Addresses #162.
git-svn-id:
file:///svn/tokudb@1068
c7de825b-a66e-492c-adef-691d508d4ae1
parent
07c01e89
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
46 deletions
+11
-46
src/tests/test_db_curs4.c
src/tests/test_db_curs4.c
+11
-46
No files found.
src/tests/test_db_curs4.c
View file @
d13076d2
...
...
@@ -31,17 +31,11 @@ struct name_key {
};
struct
primary_data
{
TIMESTAMP
creationtime
;
TIMESTAMP
expiretime
;
/* not valid if doesexpire==0 */
unsigned
char
doesexpire
;
struct
name_key
name
;
};
static
void
free_pd
(
struct
primary_data
*
pd
)
{
free
(
pd
->
name
.
name
);
free
(
pd
);
}
static
void
write_uchar_to_dbt
(
DBT
*
dbt
,
const
unsigned
char
c
)
{
assert
(
dbt
->
size
+
1
<=
dbt
->
ulen
);
((
char
*
)
dbt
->
data
)[
dbt
->
size
++
]
=
c
;
...
...
@@ -64,57 +58,30 @@ static void write_name_to_dbt (DBT *dbt, const struct name_key *nk) {
}
static
void
write_pd_to_dbt
(
DBT
*
dbt
,
const
struct
primary_data
*
pd
)
{
write_timestamp_to_dbt
(
dbt
,
pd
->
creationtime
);
write_timestamp_to_dbt
(
dbt
,
pd
->
expiretime
);
write_uchar_to_dbt
(
dbt
,
pd
->
doesexpire
);
write_name_to_dbt
(
dbt
,
&
pd
->
name
);
}
static
void
read_uchar_from_dbt
(
const
DBT
*
dbt
,
int
*
off
,
unsigned
char
*
uchar
)
{
assert
(
*
off
<
dbt
->
size
);
*
uchar
=
((
unsigned
char
*
)
dbt
->
data
)[(
*
off
)
++
];
}
static
void
read_timestamp_from_dbt
(
const
DBT
*
dbt
,
int
*
off
,
TIMESTAMP
*
ts
)
{
read_uchar_from_dbt
(
dbt
,
off
,
ts
);
}
static
void
read_name_from_dbt
(
const
DBT
*
dbt
,
int
*
off
,
struct
name_key
*
nk
)
{
unsigned
char
buf
[
1000
];
int
i
;
for
(
i
=
0
;
1
;
i
++
)
{
read_uchar_from_dbt
(
dbt
,
off
,
&
buf
[
i
]);
if
(
buf
[
i
]
==
0
)
break
;
}
nk
->
name
=
(
unsigned
char
*
)(
strdup
((
char
*
)
buf
));
}
static
void
read_pd_from_dbt
(
const
DBT
*
dbt
,
int
*
off
,
struct
primary_data
*
pd
)
{
read_timestamp_from_dbt
(
dbt
,
off
,
&
pd
->
creationtime
);
read_timestamp_from_dbt
(
dbt
,
off
,
&
pd
->
expiretime
);
read_uchar_from_dbt
(
dbt
,
off
,
&
pd
->
doesexpire
);
read_name_from_dbt
(
dbt
,
off
,
&
pd
->
name
);
}
static
int
name_offset_in_pd_dbt
(
void
)
{
assert
(
sizeof
(
TIMESTAMP
)
==
1
);
return
1
+
2
*
sizeof
(
TIMESTAMP
);
return
1
+
sizeof
(
TIMESTAMP
);
}
static
int
name_callback
(
DB
*
secondary
__attribute__
((
__unused__
)),
const
DBT
*
key
,
const
DBT
*
data
,
DBT
*
result
)
{
struct
primary_data
*
pd
=
malloc
(
sizeof
(
*
pd
));
int
off
=
0
;
read_pd_from_dbt
(
data
,
&
off
,
pd
);
static
int
buf
[
1000
];
result
->
ulen
=
1000
;
result
->
data
=
buf
;
result
->
size
=
0
;
write_name_to_dbt
(
result
,
&
pd
->
name
);
free_pd
(
pd
);
/* This one does work. */
static
char
buf
[
1000
];
char
*
rdata
=
((
char
*
)
data
->
data
)
+
name_offset_in_pd_dbt
();
int
rsize
=
data
->
size
-
name_offset_in_pd_dbt
();
memset
(
result
,
0
,
sizeof
(
*
result
));
result
->
size
=
rsize
;
result
->
data
=
buf
;
memcpy
(
buf
,
rdata
,
rsize
);
//result->data=rdata; /* This breaks bdb */
return
0
;
}
static
int
expire_callback
(
DB
*
secondary
__attribute__
((
__unused__
)),
const
DBT
*
key
,
const
DBT
*
data
,
DBT
*
result
)
{
struct
primary_data
*
d
=
data
->
data
;
if
(
d
->
doesexpire
)
{
...
...
@@ -192,9 +159,7 @@ static void insert_person (void) {
char
keyarray
[
1000
],
dataarray
[
1000
];
char
*
namearray
;
gettod
(
&
pk
.
ts
);
pd
.
creationtime
=
pk
.
ts
;
pd
.
expiretime
=
pk
.
ts
;
pd
.
expiretime
+=
128
;
pd
.
doesexpire
=
oppass
==
1
&&
(
opnum
==
2
||
opnum
==
10
||
opnum
==
22
);
if
(
oppass
==
1
&&
opnum
==
1
)
namearray
=
"Hc"
;
else
if
(
oppass
==
1
&&
opnum
==
2
)
namearray
=
"Ku"
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment