hk_column

Represents one column of a datasource. The data of the current row (set in hk_datasource) can be modified by using the functions set_asstring(), set_asbool(),set_asdouble, set_asinteger and set_asbinary(). and read by using the functions asstring(), asbool(), asdouble(), asinteger() and asbinary().

If the the datasource is in alter or create mode you can change the column definition by using the following functions: set_name(), set_columntype(), set_size(), set_notnull(), set_primary()

Inherits from hk_class.

Figure 2.3. hk_column data methods

set_asstring(value)

lets you set a new value for this object

asstring()

returns the current value as a string value

set_asdouble(value)

lets you set a new value for this object

asdouble()

returns the current value as a double value

set_asinteger(value)

lets you set a new value for this object

asinteger()

returns the current value as a integer value

is_readonly()

returns true if this column is read-only; if data can be changed it returns false

find(from_rownumber,to_rownumber,searchtext[,wholephrase[,casesensitive[,backwards]]])

searches for a specific value in a column, returns the row number if found, hk_datasource.max_rows()+1 if not found

find(searchtext[,wholephrase[,casesensitive[,backwards]]])

searches for a specific value in a column, returns the row number if found, hk_datasource.max_rows()+1 if not found. This version searches all rows of a datasource.

datasource()

returns the hk_datasource object, to which this hk_column belongs to.

count()

returns the number of rows that contain 'Not NULL' values

count(from,to)

returns the number of rows that contain 'Not NULL' values, starting at position 'from' and counting to position 'to'

sum()

returns the sum of all rows

sum(from,to)

returns the sum of all rows, starting at position 'from' and counting to position 'to'

Example 2.3. Read data

col=hk_this.datasource().column_by_name("name")
hk_this.show_warningmessage(col.asstring())

Example 2.4. Write data

col=hk_this.datasource().column_by_name("name")
col.set_asstring("my new value")

This changes the value of the current column. The data is saved either when

Example 2.5. Search data

col=hk_this.datasource().column_by_name("name")
result=col.find("Schiller")
if result > hk_this.datasource().max_rows():
     hk_this.show_warningmessage("value not found")
else:
     hk_this.show_warningmessage("Value found at row position: "+str(result))

Figure 2.4. hk_column type methods

name()

returns the name of this column

set_name(name)

sets the column name

set_columntype(type)

sets the type of the column

Possible values are

  • textcolumn

  • auto_inccolumn

  • smallintegercolumn

  • integercolumn

  • smallfloatingcolumn

  • floatingcolumn

  • datecolumn

  • datetimecolumn

  • timecolumn

  • timestampcolumn

  • binarycolumn

  • memocolumn

  • boolcolumn

  • othercolumn

columntype()

returns the type of the column.

set_size()

sets the column size (e.g. if this column was should be a textcolumn with 10 characters set the type with set_type and the size with this function)

size()

returns the column size (e.g. if this column was created as CHAR(10) it will return 10)

set_primary(primary)

if 'primary' is true the column will be part of the primary key (primary index). Can only be edited if the datasource is in the mode ALTER or CREATE.

is_primary()

returns true if this column is part of a primary key

set_notnull(notnull)

if 'notnull' true the column needs a value

is_notnull()

returns True if this column has to have a value