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

fields()

Obtain a list of columns.

int

isEmpty()

Return whether the data exists.


setObjectType( type )

Set the table.


setValue( column, value )

Set the value on the column.


setValueAsStream( column, value )

Convert the value to String and set on the column.


setValueAsDateTime( column, value )

Convert the value to DateTime and set on the column.

str

stringValues()

Obtain a String list of all values.

  int or float or str

value( column )

Obtain the value of the column.

 list[ int or float or str ]

values()

Obtain a list of all values.

int or float or str

valueByIndex( index )

Obtain the value of the column which matches the index.


  setObjectType( type:Table name )

 

  setObjectType sets the table.


        ㆍ type : Enter the name of the tables.



  Example)

   


       dbData = DataObject()

       dbData.setObjectType('PCS_MEMBER')





  setValue( column:Columns, value:Values or text )

 

  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( column:Columns, value:Stream format )

 

  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( column:Columns, value:datetime )

 

  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)


         



  int isEmpty()

 

  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.')





  int or float or str value( column:Columns )

 

  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')


       



  list[ int or float or str ] values()

 

  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


       



  str stringValues()

 

  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

             




  str fields()

 

  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

               




  int or float or str valueByIndex( index:Column index )

 

  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)