Directory
eXtremeDB_rt/samples/operationsDescription
Demonstrates basic insert, read, and update operations
Used API
Classname_fieldname_put(), Classname_fieldname_get()
Code snippet
schema.mco declare database simpledb; struct B { signed<1> i1; signed<2> i2; signed<4> i4; float f; char<10> c10; }; class A { unsigned<1> ui1; unsigned<2> ui2; unsigned<4> ui4; double d; numeric<10,3> num; decimal<10,3> dec; B b; string s; list; }; .... rc = mco_trans_start(connection, MCO_READ_WRITE, MCO_TRANS_FOREGROUND, &t); .... mco_cursor_t csr; /* Cursor to navigate database contents */ /* Allocate an object */ A_new ( t, &a ); /* Put values to scalar fields */ A_ui1_put ( &a, 1 ); A_ui2_put ( &a, 2 ); A_ui4_put ( &a, 3 ); A_d_put ( &a, d ); /* Put value to string field using db_name as a value */ A_s_put ( &a, db_name, (mco_uint2)strlen( db_name ) ); /* Put mco_int8 value to numeric field */ A_num_from_chars( &i8, "1234567"); A_num_put ( &a, i8 ); /* Put char array value to decimal field */ A_dec_to_chars( 987654321, buf, sizeof(buf)); A_dec_put_chars( &a, buf ); /* Get struct handle to write it */ A_b_write_handle ( &a, &b ); /* Put values to the struct fields */ B_i1_put ( &b, 4 ); B_i2_put ( &b, 5 ); B_i4_put ( &b, 6 ); B_f_put ( &b, f ); B_c10_put( &b, db_name, (mco_uint2)strlen( db_name ) ); rc = mco_trans_commit( t );What to expect as an output
./target/bin/operations Sample 'operations' performs basic insert, read, and update operations. eXtremeDB/rt runtime version 1.4, Debug Copyright (c) 2001-2024 McObject LLC. All Rights Reserved. Open : Successful Connect : Successful Open Transaction : Successful Commit Transaction : Successful Contents of first record A: ui1=1, ui2=2, ui4=3, d=2.200000 num=1234567000, chars(1234567.000) dec=987654321, chars(987654.321) string s=(operations), (length = 10) Struct b: b.i1=4, b.i2=5, b.i4=6, b.f=1.100000, b.c10=(operations) Using A_fixed : _a.ui1=1, _a.ui2=2, _a.ui4=3, _a.d=2.200000 Using B_fixed : _b.i1=4, _b.i2=5, _b.i4=6, _b.f=1.100000, _b.c10=(operations) Disconnect : Successful Close : Successful