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
3a5b5b0c
Commit
3a5b5b0c
authored
Jan 03, 2005
by
tomas@poseidon.ndb.mysql.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated ndbapi examples
parent
2ee205e5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
45 deletions
+37
-45
ndb/examples/ndbapi_example3/ndbapi_example3.cpp
ndb/examples/ndbapi_example3/ndbapi_example3.cpp
+6
-6
ndb/examples/ndbapi_example5/ndbapi_example5.cpp
ndb/examples/ndbapi_example5/ndbapi_example5.cpp
+22
-32
ndb/examples/ndbapi_scan_example/Makefile
ndb/examples/ndbapi_scan_example/Makefile
+2
-2
ndb/examples/ndbapi_scan_example/ndbapi_scan.cpp
ndb/examples/ndbapi_scan_example/ndbapi_scan.cpp
+7
-5
No files found.
ndb/examples/ndbapi_example3/ndbapi_example3.cpp
View file @
3a5b5b0c
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
//
//
// There are many ways to program using the NDB API. In this example
// There are many ways to program using the NDB API. In this example
// we execute two inserts in the same transaction using
// we execute two inserts in the same transaction using
// NdbConnection::
Ndb
execute(NoCommit).
// NdbConnection::execute(NoCommit).
//
//
// Transaction failing is handled by re-executing the transaction
// Transaction failing is handled by re-executing the transaction
// in case of non-permanent transaction errors.
// in case of non-permanent transaction errors.
...
@@ -86,9 +86,9 @@ void printTransactionError(NdbTransaction *ndbTransaction) {
...
@@ -86,9 +86,9 @@ void printTransactionError(NdbTransaction *ndbTransaction) {
//
//
// Example insert
// Example insert
// @param myNdb Ndb object representing NDB Cluster
// @param myNdb
Ndb object representing NDB Cluster
// @param myTransaction NdbTransaction used for transaction
// @param myTransaction NdbTransaction used for transaction
// @param error NdbError object returned in case of errors
// @param error
NdbError object returned in case of errors
// @return -1 in case of failures, 0 otherwise
// @return -1 in case of failures, 0 otherwise
//
//
int
insert
(
int
transactionId
,
NdbTransaction
*
myTransaction
)
{
int
insert
(
int
transactionId
,
NdbTransaction
*
myTransaction
)
{
...
@@ -203,10 +203,10 @@ int main()
...
@@ -203,10 +203,10 @@ int main()
exit
(
-
1
);
exit
(
-
1
);
}
}
Ndb
*
myNdb
=
new
Ndb
(
cluster_connection
,
Ndb
*
myNdb
=
new
Ndb
(
cluster_connection
,
"TEST_DB_1"
);
// Object representing the database
"TEST_DB_1"
);
// Object representing the database
if
(
myNdb
->
init
()
==
-
1
)
{
if
(
myNdb
->
init
()
==
-
1
)
{
APIERROR
(
myNdb
->
getNdbError
());
APIERROR
(
myNdb
->
getNdbError
());
exit
(
-
1
);
exit
(
-
1
);
}
}
...
...
ndb/examples/ndbapi_example5/ndbapi_example5.cpp
View file @
3a5b5b0c
...
@@ -58,8 +58,8 @@
...
@@ -58,8 +58,8 @@
int
myCreateEvent
(
Ndb
*
myNdb
,
int
myCreateEvent
(
Ndb
*
myNdb
,
const
char
*
eventName
,
const
char
*
eventName
,
const
char
*
eventTableName
,
const
char
*
eventTableName
,
const
char
**
eventCo
m
lumnName
,
const
char
**
eventColumnName
,
const
int
noEventCo
m
lumnName
);
const
int
noEventColumnName
);
int
main
()
int
main
()
{
{
...
@@ -93,39 +93,30 @@ int main()
...
@@ -93,39 +93,30 @@ int main()
Ndb
*
myNdb
=
new
Ndb
(
cluster_connection
,
Ndb
*
myNdb
=
new
Ndb
(
cluster_connection
,
"TEST_DB"
);
// Object representing the database
"TEST_DB"
);
// Object representing the database
if
(
myNdb
->
init
()
==
-
1
)
{
if
(
myNdb
->
init
()
==
-
1
)
APIERROR
(
myNdb
->
getNdbError
());
APIERROR
(
myNdb
->
getNdbError
());
exit
(
-
1
);
}
NdbDictionary
::
Dictionary
*
myDict
;
const
char
*
eventName
=
"CHNG_IN_TAB0"
;
const
char
*
eventName
=
"CHNG_IN_TAB0"
;
const
char
*
eventTableName
=
"TAB0"
;
const
char
*
eventTableName
=
"TAB0"
;
const
int
noEventColumnName
=
3
;
const
int
noEventColumnName
=
3
;
const
char
*
eventColumnName
[
noEventColumnName
]
=
const
char
*
eventColumnName
[
noEventColumnName
]
=
{
"COL0"
,
{
"COL0"
,
"COL1"
,
"COL1"
,
"COL11"
};
"COL11"
};
myDict
=
myNdb
->
getDictionary
();
// Create events
// Create events
myCreateEvent
(
myNdb
,
myCreateEvent
(
myNdb
,
eventName
,
eventName
,
eventTableName
,
eventTableName
,
eventColumnName
,
eventColumnName
,
noEventColumnName
);
noEventColumnName
);
int
j
=
0
;
int
j
=
0
;
while
(
j
<
5
)
{
while
(
j
<
5
)
{
// Start "transaction" for handling events
// Start "transaction" for handling events
NdbEventOperation
*
op
;
NdbEventOperation
*
op
;
printf
(
"create EventOperation
\n
"
);
printf
(
"create EventOperation
\n
"
);
if
((
op
=
myNdb
->
createEventOperation
(
eventName
,
100
))
==
NULL
)
{
if
((
op
=
myNdb
->
createEventOperation
(
eventName
,
100
))
==
NULL
)
printf
(
"Event operation creation failed
\n
"
);
APIERROR
(
myNdb
->
getNdbError
());
exit
(
-
1
);
}
printf
(
"get values
\n
"
);
printf
(
"get values
\n
"
);
NdbRecAttr
*
recAttr
[
noEventColumnName
];
NdbRecAttr
*
recAttr
[
noEventColumnName
];
...
@@ -139,22 +130,21 @@ int main()
...
@@ -139,22 +130,21 @@ int main()
// set up the callbacks
// set up the callbacks
printf
(
"execute
\n
"
);
printf
(
"execute
\n
"
);
if
(
op
->
execute
())
{
// This starts changes to "start flowing"
if
(
op
->
execute
())
{
// This starts changes to "start flowing"
printf
(
"operation
d
execution failed
\n
"
);
printf
(
"operation execution failed
\n
"
);
exit
(
-
1
);
exit
(
-
1
);
}
}
int
i
=
0
;
int
i
=
0
;
while
(
i
<
40
)
{
while
(
i
<
40
)
{
//printf("now waiting for event...\n");
//
printf("now waiting for event...\n");
int
r
=
myNdb
->
pollEvents
(
1000
);
// wait for event or 1000 ms
int
r
=
myNdb
->
pollEvents
(
1000
);
// wait for event or 1000 ms
if
(
r
>
0
)
{
if
(
r
>
0
)
{
//printf("got data! %d\n", r);
//
printf("got data! %d\n", r);
int
overrun
;
int
overrun
;
while
(
op
->
next
(
&
overrun
)
>
0
)
{
while
(
op
->
next
(
&
overrun
)
>
0
)
{
i
++
;
i
++
;
if
(
!
op
->
isConsistent
())
if
(
!
op
->
isConsistent
())
printf
(
"A node fail
i
ure has occured and events might be missing
\n
"
);
printf
(
"A node failure has occured and events might be missing
\n
"
);
switch
(
op
->
getEventType
())
{
switch
(
op
->
getEventType
())
{
case
NdbDictionary
:
:
Event
::
TE_INSERT
:
case
NdbDictionary
:
:
Event
::
TE_INSERT
:
printf
(
"%u INSERT: "
,
i
);
printf
(
"%u INSERT: "
,
i
);
...
@@ -190,13 +180,17 @@ int main()
...
@@ -190,13 +180,17 @@ int main()
}
else
}
else
;
//printf("timed out\n");
;
//printf("timed out\n");
}
}
// don't want to listen to eventsanymore
// don't want to listen to events
anymore
myNdb
->
dropEventOperation
(
op
);
myNdb
->
dropEventOperation
(
op
);
j
++
;
j
++
;
}
}
myDict
->
dropEvent
(
eventName
);
// remove event from database
{
NdbDictionary
::
Dictionary
*
myDict
=
myNdb
->
getDictionary
();
if
(
!
myDict
)
APIERROR
(
myNdb
->
getNdbError
());
myDict
->
dropEvent
(
eventName
);
// remove event from database
}
delete
myNdb
;
delete
myNdb
;
delete
cluster_connection
;
delete
cluster_connection
;
...
@@ -210,12 +204,8 @@ int myCreateEvent(Ndb* myNdb,
...
@@ -210,12 +204,8 @@ int myCreateEvent(Ndb* myNdb,
const
char
**
eventColumnName
,
const
char
**
eventColumnName
,
const
int
noEventColumnName
)
const
int
noEventColumnName
)
{
{
NdbDictionary
::
Dictionary
*
myDict
=
myNdb
->
getDictionary
();
NdbDictionary
::
Dictionary
*
myDict
=
myNdb
->
getDictionary
();
if
(
!
myDict
)
APIERROR
(
myNdb
->
getNdbError
());
if
(
!
myDict
)
{
printf
(
"Event Creation failedDictionary not found"
);
exit
(
-
1
);
}
NdbDictionary
::
Event
myEvent
(
eventName
);
NdbDictionary
::
Event
myEvent
(
eventName
);
myEvent
.
setTable
(
eventTableName
);
myEvent
.
setTable
(
eventTableName
);
...
...
ndb/examples/ndbapi_scan_example/Makefile
View file @
3a5b5b0c
...
@@ -9,12 +9,12 @@ LFLAGS = -Wall
...
@@ -9,12 +9,12 @@ LFLAGS = -Wall
TOP_SRCDIR
=
../../..
TOP_SRCDIR
=
../../..
INCLUDE_DIR
=
$(TOP_SRCDIR)
/ndb/include
INCLUDE_DIR
=
$(TOP_SRCDIR)
/ndb/include
LIB_DIR
=
-L
$(TOP_SRCDIR)
/ndb/src/.libs
\
LIB_DIR
=
-L
$(TOP_SRCDIR)
/ndb/src/.libs
\
-L
$(TOP_SRCDIR)
/libmysql/.libs
\
-L
$(TOP_SRCDIR)
/libmysql
_r
/.libs
\
-L
$(TOP_SRCDIR)
/mysys
-L
$(TOP_SRCDIR)
/mysys
SYS_LIB
=
SYS_LIB
=
$(TARGET)
:
$(OBJS)
$(TARGET)
:
$(OBJS)
$(CXX)
$(CXXFLAGS)
$(LFLAGS)
$(LIB_DIR)
$(OBJS)
-lndbclient
-lmysqlclient
-lmysys
$(SYS_LIB)
-o
$(TARGET)
$(CXX)
$(CXXFLAGS)
$(LFLAGS)
$(LIB_DIR)
$(OBJS)
-lndbclient
-lmysqlclient
_r
-lmysys
-lz
$(SYS_LIB)
-o
$(TARGET)
$(TARGET).o
:
$(SRCS)
$(TARGET).o
:
$(SRCS)
$(CXX)
$(CFLAGS)
-I
$(INCLUDE_DIR)
-I
$(INCLUDE_DIR)
/ndbapi
$(SRCS)
$(CXX)
$(CFLAGS)
-I
$(INCLUDE_DIR)
-I
$(INCLUDE_DIR)
/ndbapi
$(SRCS)
...
...
ndb/examples/ndbapi_scan_example/ndbapi_scan.cpp
View file @
3a5b5b0c
...
@@ -24,9 +24,12 @@
...
@@ -24,9 +24,12 @@
*
*
* Classes and methods used in this example:
* Classes and methods used in this example:
*
*
* Ndb_cluster_connection
* connect()
* wait_until_ready()
*
* Ndb
* Ndb
* init()
* init()
* waitUntilRead()
* getDictionary()
* getDictionary()
* startTransaction()
* startTransaction()
* closeTransaction()
* closeTransaction()
...
@@ -74,7 +77,6 @@
...
@@ -74,7 +77,6 @@
#include <NdbApi.hpp>
#include <NdbApi.hpp>
#include <NdbScanFilter.hpp>
// Used for cout
// Used for cout
#include <iostream>
#include <iostream>
...
@@ -235,7 +237,7 @@ int scan_delete(Ndb* myNdb,
...
@@ -235,7 +237,7 @@ int scan_delete(Ndb* myNdb,
int
deletedRows
=
0
;
int
deletedRows
=
0
;
int
check
;
int
check
;
NdbError
err
;
NdbError
err
;
Ndb
Connection
*
myTrans
;
Ndb
Transaction
*
myTrans
;
NdbScanOperation
*
myScanOp
;
NdbScanOperation
*
myScanOp
;
/**
/**
...
@@ -407,7 +409,7 @@ int scan_update(Ndb* myNdb,
...
@@ -407,7 +409,7 @@ int scan_update(Ndb* myNdb,
int
updatedRows
=
0
;
int
updatedRows
=
0
;
int
check
;
int
check
;
NdbError
err
;
NdbError
err
;
Ndb
Connection
*
myTrans
;
Ndb
Transaction
*
myTrans
;
NdbScanOperation
*
myScanOp
;
NdbScanOperation
*
myScanOp
;
/**
/**
...
@@ -588,7 +590,7 @@ int scan_print(Ndb * myNdb)
...
@@ -588,7 +590,7 @@ int scan_print(Ndb * myNdb)
int
fetchedRows
=
0
;
int
fetchedRows
=
0
;
int
check
;
int
check
;
NdbError
err
;
NdbError
err
;
Ndb
Connection
*
myTrans
;
Ndb
Transaction
*
myTrans
;
NdbScanOperation
*
myScanOp
;
NdbScanOperation
*
myScanOp
;
/* Result of reading attribute value, three columns:
/* Result of reading attribute value, three columns:
REG_NO, BRAND, and COLOR
REG_NO, BRAND, and COLOR
...
...
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