DataObject
DataObject
DataObject object is used with dbm objects. It is used to insert or update the data of databases.
Methods
The table must be set on a DataObject object, and it is able to obtain the data in the DataObject object.
Return Type |
Method |
Description |
str |
Obtain a list of columns. |
|
int |
Return whether the data exists. |
|
Set the table. |
||
Set the value on the column. |
||
Convert the value to String and set on the column. |
||
Convert the value to DateTime and set on the column. |
||
str |
Obtain a String list of all values. |
|
int or float or str |
Obtain the value of the column. |
|
list[ int or float or str ] |
Obtain a list of all values. |
|
int or float or str |
Obtain the value of the column which matches the index. |
setObjectType sets the table. ㆍ type : Enter the name of the tables. Example)
dbData = DataObject() dbData.setObjectType('PCS_MEMBER') |
setValue is a method that sets the value on columns. ㆍ column : Enter the column of tables. ㆍ value : Enter the value or text. Example)
dbData = DataObject() dbData.setObjectType('PCS_MEMBER') dbData.setValue('id', 'admin') dbData.setValue('pwd', '1234') dbData.setValue('decript','Administrator')
|
setValueAsStream is a method that saves the Stream data on columns. ㆍ column : 대Enter the column of tables. ㆍ value : Enter the Stream data. Example)
f = open('memo.txt', 'r') value = f.read() f.close()
dbData = DataObject() dbData.setObjectType('PCS_MEMBER') dbData.setValue('id','user') dbData.setValue('pwd', '1234') dbData.setValue('desc','User') dbData.setValueAsStream('memo', value) dbm.addData(dbData)
|
setValueAsDateTime is a method that converts the datetime value of scripts to the value that is able to enter. ㆍ column : Enter the column of tables. ㆍ value : Enter the datetime value of scripts. Example)
import datetime now = datetime.datetime.now() dbData.setObjectType('PCS_MEMBER') dbData.setValue('id','tester') dbData.setValue('pwd', '1234') dbData.setValue('desc','Tester') dbData.setValueAsDateTime('date', now) dbm.addData(dbData)
|
isEmpty returns whether the data exists in DataObject objects. ㆍ TRUE(1) : If the data exists in DataObject objects, return TRUE. ㆍ FALSE(0) : If the data does not exist in DataObject objects, return FALSE. Example)
dataList = dbm.cmd2('SELECT * FROM PCS_MEMBER') data1 = DataObject() data1 = dataList[0] if data1.isEmpty(): app.messageBox('No data in DataObjects.') else: app.messageBox('The data exists in DataObjects.') |
value finds the column in DataObject objects and returns that data. ㆍ column : Enter the column of tables. ㆍ Return values - Return the value of the column you entered. - Value has a data type of format. - Return it exists or not. Example)
dataList = dbm.cmd2('SELECT * FROM PCS_MEMBER') data = dataList[0] print ‘item is ‘, data.value('id'), ', ', data.value('pwd'), ', ', data.value('desc')
|
values returns the values that the DataObject object had. ㆍ Return values - Convert the value of columns you entered into a form of a list. - Value has a data type of format. Example)
dataList = dbm.cmd2('SELECT * FROM PCS_MEMBER') data = dataList[0] v = data.values() print 'values : ', v
|
stringValues converts the value ofConvert the value to a form of String list and return. Example)
dataList = dbm.cmd2('SELECT * FROM PCS_MEMBER') data = dataList[0] v = data.stringValues() print 'stringValues : ', v
|
fields method returns a list of columns that a DataObject object has. ㆍ Return value - Convert the value to a form of String list and return. Example)
dataList = dbm.cmd2('SELECT * FROM PCS_MEMBER') data = dataList[0] v = data.fields() print 'fields : ', v
|
valueByIndex finds the value of that column which matched to the index and returns the data. ㆍ index : Enter the index of columns of that table. ㆍ Return values - Return the value of columns. - Value has a data type of format. Example)
dataList = dbm.cmd2('SELECT id, pwd, desc FROM PCS_MEMBER') data = dataList[0] data.valueByIndex(1) data.valueByIndex(2) data.valueByIndex(3) print 'id is', data.valueByIndex(1), 'pwd is', data.valueByIndex(2), 'desc is', data.valueByIndex(3) |