Esempio n. 1
0
print mySession, '\n'

if mySession.uri == __displayuridb:
    print 'Session using right URI\n'
else:
    print 'Session using wrong URI\n'

mySession.close()

#@ mysqlx module: get_node_session through data and password
data = {'host': __host, 'port': __port, 'schema': __schema, 'dbUser': __user}

mySession = mysqlx.get_node_session(data, __pwd)

print mySession, '\n'

if mySession.uri == __displayuridb:
    print 'Session using right URI\n'
else:
    print 'Session using wrong URI\n'

mySession.close()

# @# mysqlx module: expression errors
# expr = mysqlx.expr()
# expr = mysqlx.expr(5)

#@ mysqlx module: expression
expr = mysqlx.expr('5+6')
print expr
Esempio n. 2
0
                                                                  'another', 5)

#@# CollectionModify: Error conditions on execute
crud = collection.modify('name = :data and age > :years').set(
    'hobby', 'swim').execute()
crud = collection.modify('name = :data and age > :years').set(
    'hobby', 'swim').bind('years', 5).execute()

# ---------------------------------------
# Collection.Modify Unit Testing: Execution
# ---------------------------------------

#@# CollectionModify: Set Execution
#! [CollectionModify: Set Execution]
result = collection.modify('name = "brian"').set('alias', 'bri').set(
    'last_name', 'black').set('age', mysqlx.expr('13+1')).execute()
print('Set Affected Rows:', result.affected_items_count, '\n')
#! [CollectionModify: Set Execution]

result = collection.find('name = "brian"').execute()
doc = result.fetch_one()
print(dir(doc))

#@# CollectionModify: Set Execution Binding Array
#! [CollectionModify: Set Binding Array]
result = collection.modify('name = "brian"').set(
    'hobbies',
    mysqlx.expr(':list')).bind('list',
                               ['soccer', 'dance', 'reading']).execute()
print('Set Affected Rows:', result.affected_items_count, '\n')
#! [CollectionModify: Set Binding Array]
Esempio n. 3
0
validate_crud_functions(crud, ['add', 'execute'])

#@ CollectionAdd: valid operations after execute
result = crud.execute()
validate_crud_functions(crud, ['add', 'execute'])


# ---------------------------------------------
# Collection.add Unit Testing: Error Conditions
# ---------------------------------------------

#@# CollectionAdd: Error conditions on add
crud = collection.add()
crud = collection.add(45)
crud = collection.add(['invalid data'])
crud = collection.add(mysqlx.expr('5+1'))
crud = collection.add([{'name': 'sample'}, 'error']);
crud = collection.add({'name': 'sample'}, 'error');


# ---------------------------------------
# Collection.Add Unit Testing: Execution
# ---------------------------------------

#@<> Collection.add execution  {VER(>=8.0.11)}
result = collection.add({ "name": 'document01', "Passed": 'document', "count": 1 }).execute()
EXPECT_EQ(1, result.affected_item_count)
EXPECT_EQ(1, result.affected_items_count)
EXPECT_EQ(1, len(result.generated_ids))
EXPECT_EQ(1, len(result.get_generated_ids()))
# WL11435_FR3_1
Esempio n. 4
0
  mySession.start_transaction()
  movies.remove(i).execute()
  mySession.rollback()

#@ IN basic - table select
for i in fr1_cases_tbl:
  print i
  tabl.select().where(i).execute().fetch_all()
  tabl.select().order_by([i]).execute().fetch_all()
  # tabl.select([i]).groupBy([i]).having(i).execute().fetch_all()

#@ IN basic - table update
for i in fr1_cases_tbl:
  print i
  mySession.start_transaction()
  tabl.update().set("doc", mysqlx.expr("doc")).where(i).execute()
  mySession.rollback()

#@ IN basic - table delete
for i in fr1_cases_tbl:
  print i
  mySession.start_transaction()
  tabl.delete().where(i).execute()
  mySession.rollback()

#@WL10848 F2 - The evaluation of the IN operation between 2 operands is equivalent to a call to the JSON_CONTAINS() function with said operands Rules defined for JSON_CONTAINS():

# A candidate scalar is contained in a target scalar if and only if they are comparable and are equal. Two scalar values are comparable if they have the same JSON_TYPE() types, with the exception that values of types INTEGER and DECIMAL are also comparable to each other.
# A candidate array is contained in a target array if and only if every element in the candidate is contained in some element of the target
# A candidate nonarray is contained in a target array if and only if the candidate is contained in some element of the target.
# A candidate object is contained in a target object if and only if for each key in the candidate there is a key with the same name in the target and the value associated with the candidate key is contained in the value associated with the target key.
# ---------------------------------------
# Table.Modify Unit Testing: Execution
# ---------------------------------------
#@# TableUpdate: simple test
result = result = table.update().set('name',
                                     'aline').where('age = 13').execute()
print('Affected Rows:', result.affected_items_count, '\n')

result = table.select().where('name = "aline"').execute()
record = result.fetch_one()
print("Updated Record:", record.name, record.age)

#@ TableUpdate: test using expression
result = table.update().set('age',
                            mysqlx.expr('13+10')).where('age = 13').execute()
print('Affected Rows:', result.affected_items_count, '\n')

result = table.select().where('age = 23').execute()
record = result.fetch_one()
print("Updated Record:", record.name, record.age)

#@ TableUpdate: test using limits
result = table.update().set(
    'age', mysqlx.expr(':new_year')).where('age = :old_year').limit(2).bind(
        'new_year', 16).bind('old_year', 15).execute()
print('Affected Rows:', result.affected_items_count, '\n')

records = table.select().where('age = 16').execute().fetch_all()
print('With 16 Years:', len(records), '\n')
print('Type:', column.get_type())
print('Length:', column.get_length())
print('Fractional Digits:', column.get_fractional_digits())
print('Is Number Signed:', column.is_number_signed())
print('Collation Name:', column.get_collation_name())
print('Charset Name:', column.get_character_set_name())
print('Is ZeroFill:', column.is_zero_fill())

# Metadata Validation On Other Types
result = mySession.sql(
    "create table table2 (one json, two char(5) primary key, three varchar(20), four text, five time, six date, seven timestamp, eight set('1','2','3'), nine enum ('a','b','c'), ten varbinary(15), eleven blob)"
).execute()
table = schema.get_table('table2')

result = table.insert().values('{"name":"John", "Age":23}', 'test', 'sample',
                               'a_text', mysqlx.expr('NOW()'),
                               mysqlx.expr('CURDATE()'), mysqlx.expr('NOW()'),
                               '2', 'c', '¡¡¡¡', '£€¢').execute()

result = table.select().execute()
columns = result.get_columns()
column_index = 0

#@ Metadata on Json Column
column = columns[column_index]
field = row[column_index]
column_index += 1
print('Field Type: ', type(field))
print('Schema Name:', column.get_schema_name())
print('Table Name:', column.get_table_name())
print('Table Label:', column.get_table_label())
Esempio n. 7
0
all_members = dir(mysqlx)

# Remove the python built in members
exports = []
for member in all_members:
    if not member.startswith('__'):
        exports.append(member)

print('Exported Items:', len(exports))

print('get_session:', type(mysqlx.get_session), '\n')
print('expr:', type(mysqlx.expr), '\n')
print('dateValue:', type(mysqlx.date_value), '\n')
print('help:', type(mysqlx.date_value), '\n')
print('Type:', mysqlx.Type, '\n')
print('LockContention:', mysqlx.LockContention, '\n')

#@# mysqlx module: expression errors
expr = mysqlx.expr()
expr = mysqlx.expr(5)

#@ mysqlx module: expression
expr = mysqlx.expr('5+6')
print(expr)

#@ mysqlx module: date_value() diffrent parameters
mysqlx.date_value(2025, 10, 15)
mysqlx.date_value(2017, 12, 10, 10, 10, 10)
mysqlx.date_value(2017, 12, 10, 10, 10, 10, 500000)
mysqlx.date_value(2017, 12, 10, 10, 10, 10, 599999)
Esempio n. 8
0
validate_crud_functions(crud, ['add', 'execute'])

#@ CollectionAdd: valid operations after execute
result = crud.execute()
validate_crud_functions(crud, ['add', 'execute'])


# ---------------------------------------------
# Collection.add Unit Testing: Error Conditions
# ---------------------------------------------

#@# CollectionAdd: Error conditions on add
crud = collection.add()
crud = collection.add(45)
crud = collection.add(['invalid data'])
crud = collection.add(mysqlx.expr('5+1'))
crud = collection.add([{'name': 'sample'}, 'error']);
crud = collection.add({'name': 'sample'}, 'error');


# ---------------------------------------
# Collection.Add Unit Testing: Execution
# ---------------------------------------

#@<> Collection.add execution  {VER(>=8.0.11)}
result = collection.add({ "name": 'document01', "Passed": 'document', "count": 1 }).execute()
EXPECT_EQ(1, result.affected_item_count)
EXPECT_EQ(1, result.affected_items_count)
EXPECT_EQ(1, len(result.generated_ids))
EXPECT_EQ(1, len(result.get_generated_ids()))
# WL11435_FR3_1
Esempio n. 9
0

# ----------------------------------------------
# Collection.Find Unit Testing: Error Conditions
# ----------------------------------------------

#@# CollectionFind: Error conditions on find
crud = collection.find(5)
crud = collection.find('test = "2')

#@# CollectionFind: Error conditions on fields
crud = collection.find().fields()
crud = collection.find().fields(5)
crud = collection.find().fields([])
crud = collection.find().fields(['name as alias', 5])
crud = collection.find().fields(mysqlx.expr('concat(field, "whatever")'))
crud = collection.find().fields('name as alias', 5)

#@# CollectionFind: Error conditions on group_by
crud = collection.find().group_by()
crud = collection.find().group_by(5)
crud = collection.find().group_by([])
crud = collection.find().group_by(['name', 5])
crud = collection.find().group_by('name', 5)

#@# CollectionFind: Error conditions on having
crud = collection.find().group_by(['name']).having()
crud = collection.find().group_by(['name']).having(5)

#@# CollectionFind: Error conditions on sort
crud = collection.find().sort()
#@# CollectionModify: Error conditions on bind
crud = collection.modify('name = :data and age > :years').set('hobby', 'swim').bind()
crud = collection.modify('name = :data and age > :years').set('hobby', 'swim').bind(5, 5)
crud = collection.modify('name = :data and age > :years').set('hobby', 'swim').bind('another', 5)

#@# CollectionModify: Error conditions on execute
crud = collection.modify('name = :data and age > :years').set('hobby', 'swim').execute()
crud = collection.modify('name = :data and age > :years').set('hobby', 'swim').bind('years', 5).execute()


# ---------------------------------------
# Collection.Modify Unit Testing: Execution
# ---------------------------------------

#@# CollectionModify: Set Execution
result = collection.modify('name = "brian"').set('alias', 'bri').set('last_name', 'black').set('age', mysqlx.expr('13+1')).execute()
print 'Set Affected Rows:', result.affected_items_count, '\n'

result = collection.find('name = "brian"').execute()
doc = result.fetch_one()
print dir(doc)

#@# CollectionModify: Set Execution Binding Array
result = collection.modify('name = "brian"').set('hobbies', mysqlx.expr(':list')).bind('list', ['soccer', 'dance', 'reading']).execute()
print 'Set Affected Rows:', result.affected_items_count, '\n'

result = collection.find('name = "brian"').execute()
doc = result.fetch_one()
print dir(doc)
print doc.hobbies[0]
print doc.hobbies[1]
Esempio n. 11
0
# Remove the python built in members
exports = []
for member in all_members:
  if not member.startswith('__'):
    exports.append(member)

print 'Exported Items:', len(exports)

print 'get_session:', type(mysqlx.get_session), '\n'
print 'expr:', type(mysqlx.expr), '\n'
print 'dateValue:', type(mysqlx.date_value), '\n'
print 'help:', type(mysqlx.date_value), '\n'
print 'Type:', mysqlx.Type, '\n'
print 'LockContention:', mysqlx.LockContention, '\n'

#@# mysqlx module: expression errors
expr = mysqlx.expr()
expr = mysqlx.expr(5)

#@ mysqlx module: expression
expr = mysqlx.expr('5+6')
print expr

#@ mysqlx module: date_value() diffrent parameters
mysqlx.date_value(2025, 10, 15);
mysqlx.date_value(2017, 12, 10, 10, 10, 10);
mysqlx.date_value(2017, 12, 10, 10, 10, 10, 500000);
mysqlx.date_value(2017, 12, 10, 10, 10, 10, 599999);

print 'Table Label:', column.get_table_label()
print 'Column Name:', column.get_column_name()
print 'Column Label:', column.get_column_label()
print 'Type:', column.get_type()
print 'Length:', column.get_length()
print 'Fractional Digits:', column.get_fractional_digits()
print 'Is Number Signed:', column.is_number_signed()
print 'Collation Name:', column.get_collation_name()
print 'Charset Name:', column.get_character_set_name()
print 'Is ZeroFill:', column.is_zero_fill()

# Metadata Validation On Other Types
result = mySession.sql("create table table2 (one json, two char(5) primary key, three varchar(20), four text, five time, six date, seven timestamp, eight set('1','2','3'), nine enum ('a','b','c'), ten varbinary(15), eleven blob)").execute()
table = schema.get_table('table2')

result = table.insert().values('{"name":"John", "Age":23}', 'test', 'sample', 'a_text', mysqlx.expr('NOW()'), mysqlx.expr('CURDATE()'), mysqlx.expr('NOW()'), '2','c', '¡¡¡¡', '£€¢').execute()

result = table.select().execute()
columns = result.get_columns()
column_index = 0

#@ Metadata on Json Column
column = columns[column_index]
field = row[column_index]
column_index += 1
print 'Field Type: ', type(field)
print 'Schema Name:', column.get_schema_name()
print 'Table Name:', column.get_table_name()
print 'Table Label:', column.get_table_label()
print 'Column Name:', column.get_column_name()
print 'Column Label:', column.get_column_label()
validate_crud_functions(crud, ['add', 'execute'])

#@ CollectionAdd: valid operations after execute
result = crud.execute()
validate_crud_functions(crud, ['add', 'execute'])


# ---------------------------------------------
# Collection.add Unit Testing: Error Conditions
# ---------------------------------------------

#@# CollectionAdd: Error conditions on add
crud = collection.add()
crud = collection.add(45)
crud = collection.add(['invalid data'])
crud = collection.add(mysqlx.expr('5+1'))
crud = collection.add({'_id':45, 'name': 'sample'});
crud = collection.add([{'name': 'sample'}, 'error']);
crud = collection.add({'name': 'sample'}, 'error');


# ---------------------------------------
# Collection.Add Unit Testing: Execution
# ---------------------------------------

#@ Collection.add execution
result = collection.add({ "name": 'my first', "Passed": 'document', "count": 1 }).execute()
print "Affected Rows Single:", result.affected_item_count, "\n"
print "last_document_id Single:", result.last_document_id
print "get_last_document_id Single:", result.get_last_document_id()
print "#last_document_ids Single:", len(result.last_document_ids)
Esempio n. 14
0
                                                              'swim').bind(
                                                                  'another', 5)

#@# CollectionModify: Error conditions on execute
crud = collection.modify('name = :data and age > :years').set(
    'hobby', 'swim').execute()
crud = collection.modify('name = :data and age > :years').set(
    'hobby', 'swim').bind('years', 5).execute()

# ---------------------------------------
# Collection.Modify Unit Testing: Execution
# ---------------------------------------

#@# CollectionModify: Set Execution
result = collection.modify('name = "brian"').set('alias', 'bri').set(
    'last_name', 'black').set('age', mysqlx.expr('13+1')).execute()
print 'Set Affected Rows:', result.affected_item_count, '\n'

result = collection.find('name = "brian"').execute()
doc = result.fetch_one()
print dir(doc)

#@# CollectionModify: Set Execution Binding Array
result = collection.modify('name = "brian"').set(
    'hobbies',
    mysqlx.expr(':list')).bind('list',
                               ['soccer', 'dance', 'reading']).execute()
print 'Set Affected Rows:', result.affected_item_count, '\n'

result = collection.find('name = "brian"').execute()
doc = result.fetch_one()
Esempio n. 15
0

# ----------------------------------------------
# Collection.Find Unit Testing: Error Conditions
# ----------------------------------------------

#@# CollectionFind: Error conditions on find
crud = collection.find(5)
crud = collection.find('test = "2')

#@# CollectionFind: Error conditions on fields
crud = collection.find().fields()
crud = collection.find().fields(5)
crud = collection.find().fields([])
crud = collection.find().fields(['name as alias', 5])
crud = collection.find().fields(mysqlx.expr('concat(field, "whatever")'));
crud = collection.find().fields('name as alias', 5)

#@# CollectionFind: Error conditions on group_by
crud = collection.find().group_by()
crud = collection.find().group_by(5)
crud = collection.find().group_by([])
crud = collection.find().group_by(['name', 5])
crud = collection.find().group_by('name', 5)

#@# CollectionFind: Error conditions on having
crud = collection.find().group_by(['name']).having()
crud = collection.find().group_by(['name']).having(5)

#@# CollectionFind: Error conditions on sort
crud = collection.find().sort()
Esempio n. 16
0
crud = table.update().set('age', 17).where('name = :data and age > :years').bind('years', 5).execute()


# ---------------------------------------
# Table.Modify Unit Testing: Execution
# ---------------------------------------
#@# TableUpdate: simple test
result = result = table.update().set('name', 'aline').where('age = 13').execute()
print 'Affected Rows:', result.affected_items_count, '\n'

result = table.select().where('name = "aline"').execute()
record = result.fetch_one()
print "Updated Record:", record.name, record.age

#@ TableUpdate: test using expression
result = table.update().set('age', mysqlx.expr('13+10')).where('age = 13').execute()
print 'Affected Rows:', result.affected_items_count, '\n'

result = table.select().where('age = 23').execute()
record = result.fetch_one()
print "Updated Record:", record.name, record.age

#@ TableUpdate: test using limits
result = table.update().set('age', mysqlx.expr(':new_year')).where('age = :old_year').limit(2).bind('new_year', 16).bind('old_year', 15).execute()
print 'Affected Rows:', result.affected_items_count, '\n'

records = table.select().where('age = 16').execute().fetch_all()
print 'With 16 Years:', len(records), '\n'

records = table.select().where('age = 15').execute().fetch_all()
print 'With 15 Years:', len(records), '\n'