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
bf24a1a9
Commit
bf24a1a9
authored
Apr 10, 2006
by
unknown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make line endings consistent, use Unix format
parent
cfde621e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
147 additions
and
0 deletions
+147
-0
libmysql/mytest.c
libmysql/mytest.c
+147
-0
No files found.
libmysql/mytest.c
View file @
bf24a1a9
/*C4*/
/*C4*/
/****************************************************************/
/****************************************************************/
/* Author: Jethro Wright, III TS : 3/ 4/1998 9:15 */
/* Author: Jethro Wright, III TS : 3/ 4/1998 9:15 */
/* Date: 02/18/1998 */
/* Date: 02/18/1998 */
/* mytest.c : do some testing of the libmySQL.DLL.... */
/* mytest.c : do some testing of the libmySQL.DLL.... */
/* */
/* */
/* History: */
/* History: */
/* 02/18/1998 jw3 also sprach zarathustra.... */
/* 02/18/1998 jw3 also sprach zarathustra.... */
/****************************************************************/
/****************************************************************/
#include <windows.h>
#include <windows.h>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
#include <mysql.h>
#include <mysql.h>
#define DEFALT_SQL_STMT "SELECT * FROM db"
#define DEFALT_SQL_STMT "SELECT * FROM db"
#ifndef offsetof
#ifndef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif
#endif
/********************************************************
/********************************************************
**
**
** main :-
** main :-
**
**
********************************************************/
********************************************************/
int
int
main
(
int
argc
,
char
*
argv
[]
)
main
(
int
argc
,
char
*
argv
[]
)
{
{
char
szSQL
[
200
],
aszFlds
[
25
][
25
],
szDB
[
50
]
;
char
szSQL
[
200
],
aszFlds
[
25
][
25
],
szDB
[
50
]
;
const
char
*
pszT
;
const
char
*
pszT
;
int
i
,
j
,
k
,
l
,
x
;
int
i
,
j
,
k
,
l
,
x
;
MYSQL
*
myData
;
MYSQL
*
myData
;
MYSQL_RES
*
res
;
MYSQL_RES
*
res
;
MYSQL_FIELD
*
fd
;
MYSQL_FIELD
*
fd
;
MYSQL_ROW
row
;
MYSQL_ROW
row
;
//....just curious....
//....just curious....
printf
(
"sizeof( MYSQL ) == %d
\n
"
,
(
int
)
sizeof
(
MYSQL
)
)
;
printf
(
"sizeof( MYSQL ) == %d
\n
"
,
(
int
)
sizeof
(
MYSQL
)
)
;
if
(
argc
==
2
)
if
(
argc
==
2
)
{
{
strcpy
(
szDB
,
argv
[
1
]
)
;
strcpy
(
szDB
,
argv
[
1
]
)
;
strcpy
(
szSQL
,
DEFALT_SQL_STMT
)
;
strcpy
(
szSQL
,
DEFALT_SQL_STMT
)
;
if
(
!
strcmp
(
szDB
,
"--debug"
))
if
(
!
strcmp
(
szDB
,
"--debug"
))
{
{
strcpy
(
szDB
,
"mysql"
)
;
strcpy
(
szDB
,
"mysql"
)
;
printf
(
"Some mysql struct information (size and offset):
\n
"
);
printf
(
"Some mysql struct information (size and offset):
\n
"
);
printf
(
"net:
\t
%3d %3d
\n
"
,(
int
)
sizeof
(
myData
->
net
),
printf
(
"net:
\t
%3d %3d
\n
"
,(
int
)
sizeof
(
myData
->
net
),
(
int
)
offsetof
(
MYSQL
,
net
));
(
int
)
offsetof
(
MYSQL
,
net
));
printf
(
"host:
\t
%3d %3d
\n
"
,(
int
)
sizeof
(
myData
->
host
),
printf
(
"host:
\t
%3d %3d
\n
"
,(
int
)
sizeof
(
myData
->
host
),
...
@@ -75,101 +124,199 @@ main( int argc, char * argv[] )
...
@@ -75,101 +124,199 @@ main( int argc, char * argv[] )
printf
(
"options:
\t
%3d %3d
\n
"
,(
int
)
sizeof
(
myData
->
options
),
printf
(
"options:
\t
%3d %3d
\n
"
,(
int
)
sizeof
(
myData
->
options
),
(
int
)
offsetof
(
MYSQL
,
options
));
(
int
)
offsetof
(
MYSQL
,
options
));
puts
(
""
);
puts
(
""
);
}
}
}
}
else
if
(
argc
>
2
)
{
else
if
(
argc
>
2
)
{
strcpy
(
szDB
,
argv
[
1
]
)
;
strcpy
(
szDB
,
argv
[
1
]
)
;
strcpy
(
szSQL
,
argv
[
2
]
)
;
strcpy
(
szSQL
,
argv
[
2
]
)
;
}
}
else
{
else
{
strcpy
(
szDB
,
"mysql"
)
;
strcpy
(
szDB
,
"mysql"
)
;
strcpy
(
szSQL
,
DEFALT_SQL_STMT
)
;
strcpy
(
szSQL
,
DEFALT_SQL_STMT
)
;
}
}
//....
//....
if
(
(
myData
=
mysql_init
((
MYSQL
*
)
0
))
&&
if
(
(
myData
=
mysql_init
((
MYSQL
*
)
0
))
&&
mysql_real_connect
(
myData
,
NULL
,
NULL
,
NULL
,
NULL
,
MYSQL_PORT
,
mysql_real_connect
(
myData
,
NULL
,
NULL
,
NULL
,
NULL
,
MYSQL_PORT
,
NULL
,
0
)
)
NULL
,
0
)
)
{
{
myData
->
reconnect
=
1
;
myData
->
reconnect
=
1
;
if
(
mysql_select_db
(
myData
,
szDB
)
<
0
)
{
if
(
mysql_select_db
(
myData
,
szDB
)
<
0
)
{
printf
(
"Can't select the %s database !
\n
"
,
szDB
)
;
printf
(
"Can't select the %s database !
\n
"
,
szDB
)
;
mysql_close
(
myData
)
;
mysql_close
(
myData
)
;
return
2
;
return
2
;
}
}
}
}
else
{
else
{
printf
(
"Can't connect to the mysql server on port %d !
\n
"
,
printf
(
"Can't connect to the mysql server on port %d !
\n
"
,
MYSQL_PORT
)
;
MYSQL_PORT
)
;
mysql_close
(
myData
)
;
mysql_close
(
myData
)
;
return
1
;
return
1
;
}
}
//....
//....
if
(
!
mysql_query
(
myData
,
szSQL
)
)
{
if
(
!
mysql_query
(
myData
,
szSQL
)
)
{
res
=
mysql_store_result
(
myData
)
;
res
=
mysql_store_result
(
myData
)
;
i
=
(
int
)
mysql_num_rows
(
res
)
;
l
=
1
;
i
=
(
int
)
mysql_num_rows
(
res
)
;
l
=
1
;
printf
(
"Query: %s
\n
Number of records found: %ld
\n
"
,
szSQL
,
i
)
;
printf
(
"Query: %s
\n
Number of records found: %ld
\n
"
,
szSQL
,
i
)
;
//....we can get the field-specific characteristics here....
//....we can get the field-specific characteristics here....
for
(
x
=
0
;
fd
=
mysql_fetch_field
(
res
)
;
x
++
)
for
(
x
=
0
;
fd
=
mysql_fetch_field
(
res
)
;
x
++
)
strcpy
(
aszFlds
[
x
],
fd
->
name
)
;
strcpy
(
aszFlds
[
x
],
fd
->
name
)
;
//....
//....
while
(
row
=
mysql_fetch_row
(
res
)
)
{
while
(
row
=
mysql_fetch_row
(
res
)
)
{
j
=
mysql_num_fields
(
res
)
;
j
=
mysql_num_fields
(
res
)
;
printf
(
"Record #%ld:-
\n
"
,
l
++
)
;
printf
(
"Record #%ld:-
\n
"
,
l
++
)
;
for
(
k
=
0
;
k
<
j
;
k
++
)
for
(
k
=
0
;
k
<
j
;
k
++
)
printf
(
" Fld #%d (%s): %s
\n
"
,
k
+
1
,
aszFlds
[
k
],
printf
(
" Fld #%d (%s): %s
\n
"
,
k
+
1
,
aszFlds
[
k
],
(((
row
[
k
]
==
NULL
)
||
(
!
strlen
(
row
[
k
])))
?
"NULL"
:
row
[
k
]))
;
(((
row
[
k
]
==
NULL
)
||
(
!
strlen
(
row
[
k
])))
?
"NULL"
:
row
[
k
]))
;
puts
(
"==============================
\n
"
)
;
puts
(
"==============================
\n
"
)
;
}
}
mysql_free_result
(
res
)
;
mysql_free_result
(
res
)
;
}
}
else
printf
(
"Couldn't execute %s on the server !
\n
"
,
szSQL
)
;
else
printf
(
"Couldn't execute %s on the server !
\n
"
,
szSQL
)
;
//....
//....
puts
(
"==== Diagnostic info ===="
)
;
puts
(
"==== Diagnostic info ===="
)
;
pszT
=
mysql_get_client_info
()
;
pszT
=
mysql_get_client_info
()
;
printf
(
"Client info: %s
\n
"
,
pszT
)
;
printf
(
"Client info: %s
\n
"
,
pszT
)
;
//....
//....
pszT
=
mysql_get_host_info
(
myData
)
;
pszT
=
mysql_get_host_info
(
myData
)
;
printf
(
"Host info: %s
\n
"
,
pszT
)
;
printf
(
"Host info: %s
\n
"
,
pszT
)
;
//....
//....
pszT
=
mysql_get_server_info
(
myData
)
;
pszT
=
mysql_get_server_info
(
myData
)
;
printf
(
"Server info: %s
\n
"
,
pszT
)
;
printf
(
"Server info: %s
\n
"
,
pszT
)
;
//....
//....
res
=
mysql_list_processes
(
myData
)
;
l
=
1
;
res
=
mysql_list_processes
(
myData
)
;
l
=
1
;
if
(
res
)
if
(
res
)
{
{
for
(
x
=
0
;
fd
=
mysql_fetch_field
(
res
)
;
x
++
)
for
(
x
=
0
;
fd
=
mysql_fetch_field
(
res
)
;
x
++
)
strcpy
(
aszFlds
[
x
],
fd
->
name
)
;
strcpy
(
aszFlds
[
x
],
fd
->
name
)
;
while
(
row
=
mysql_fetch_row
(
res
)
)
{
while
(
row
=
mysql_fetch_row
(
res
)
)
{
j
=
mysql_num_fields
(
res
)
;
j
=
mysql_num_fields
(
res
)
;
printf
(
"Process #%ld:-
\n
"
,
l
++
)
;
printf
(
"Process #%ld:-
\n
"
,
l
++
)
;
for
(
k
=
0
;
k
<
j
;
k
++
)
for
(
k
=
0
;
k
<
j
;
k
++
)
printf
(
" Fld #%d (%s): %s
\n
"
,
k
+
1
,
aszFlds
[
k
],
printf
(
" Fld #%d (%s): %s
\n
"
,
k
+
1
,
aszFlds
[
k
],
(((
row
[
k
]
==
NULL
)
||
(
!
strlen
(
row
[
k
])))
?
"NULL"
:
row
[
k
]))
;
(((
row
[
k
]
==
NULL
)
||
(
!
strlen
(
row
[
k
])))
?
"NULL"
:
row
[
k
]))
;
puts
(
"==============================
\n
"
)
;
puts
(
"==============================
\n
"
)
;
}
}
}
}
else
else
{
{
printf
(
"Got error %s when retreiving processlist
\n
"
,
mysql_error
(
myData
));
printf
(
"Got error %s when retreiving processlist
\n
"
,
mysql_error
(
myData
));
}
}
//....
//....
res
=
mysql_list_tables
(
myData
,
"%"
)
;
l
=
1
;
res
=
mysql_list_tables
(
myData
,
"%"
)
;
l
=
1
;
for
(
x
=
0
;
fd
=
mysql_fetch_field
(
res
)
;
x
++
)
for
(
x
=
0
;
fd
=
mysql_fetch_field
(
res
)
;
x
++
)
strcpy
(
aszFlds
[
x
],
fd
->
name
)
;
strcpy
(
aszFlds
[
x
],
fd
->
name
)
;
while
(
row
=
mysql_fetch_row
(
res
)
)
{
while
(
row
=
mysql_fetch_row
(
res
)
)
{
j
=
mysql_num_fields
(
res
)
;
j
=
mysql_num_fields
(
res
)
;
printf
(
"Table #%ld:-
\n
"
,
l
++
)
;
printf
(
"Table #%ld:-
\n
"
,
l
++
)
;
for
(
k
=
0
;
k
<
j
;
k
++
)
for
(
k
=
0
;
k
<
j
;
k
++
)
printf
(
" Fld #%d (%s): %s
\n
"
,
k
+
1
,
aszFlds
[
k
],
printf
(
" Fld #%d (%s): %s
\n
"
,
k
+
1
,
aszFlds
[
k
],
(((
row
[
k
]
==
NULL
)
||
(
!
strlen
(
row
[
k
])))
?
"NULL"
:
row
[
k
]))
;
(((
row
[
k
]
==
NULL
)
||
(
!
strlen
(
row
[
k
])))
?
"NULL"
:
row
[
k
]))
;
puts
(
"==============================
\n
"
)
;
puts
(
"==============================
\n
"
)
;
}
}
//....
//....
pszT
=
mysql_stat
(
myData
)
;
pszT
=
mysql_stat
(
myData
)
;
puts
(
pszT
)
;
puts
(
pszT
)
;
//....
//....
mysql_close
(
myData
)
;
mysql_close
(
myData
)
;
return
0
;
return
0
;
}
}
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