Plugin:MirLua/Module/m database

From Miranda NG
Jump to: navigation, search
This page contains changes which are not marked for translation.

Allows you to access data and contacts in user profile database.

Include module: local db = require('m_database')

Contacts

Contacts

Iterator for list of contacts.

Parameters

Parameter name Required Type Description
name Yes string Protocol name.

Result

     Type: number

     Returns contact number. The list ends in element with nil value.

Example

for hContact in db.Contacts('JABBER_1') do

 print(db.GetSetting(hContact, 'JABBER_1', 'Nick'))

end

Events

GetEventCount

Number of events for a contact.

Parameters

Parameter name Required Type Description
hContact Yes number Contact number.

Result

     Type: number

     Returns number of events.

Example

db.GetEventCount(hContact)


Events

Iterator for contact's event list from the first to the last.

Parameters

Parameter name Required Type Description
hContact Yes number Contact number.

Result

     Type: number

     Returns event number. The list ends in element with nil value.

Example

for hEvent in db.Events(hContact) do

 local event = totable(hEvent, "DBEVENTINFO")
 print(event.Timestamp, event.Blob)

end


EventsFromEnd

Iterator for contact's event list from the last to the first.

Parameters

Parameter name Required Type Description
hContact Yes number Contact number.

Result

     Type: number

     Returns event number. The list ends in element with nil value.

Example

for hEvent in db.EventsFromEnd(hContact) do

 local event = totable(hEvent, "DBEVENTINFO")
 print(event.Timestamp, event.Blob)

end

Settings

GetSetting

Returns value of a setting.

Parameters

Parameter name Required Type Description
hContact Yes number Contact number or nil.
module Yes string Module name.
setting Yes string Setting name.
value No number, string Default value.

Result

     Type: number

     Returns value of a setting or default value or nil.

Example

db.GetSetting(nil, 'test', 'some')


Settings

Iterator for module (group of settings).

Parameters

Parameter name Required Type Description
hContact Yes number Contact number or nil.
module Yes string Module name.

Result

     Type: number

     Returns module name. The list ends in element with nil value.

Example

for setting in db.Settings(nil, 'CList') do

 local message = string.format("%s/%s = ", 'CList', setting, ...)
  .. db.GetSetting(nil, 'CList', setting)
 print(message)

end


WriteSetting

Saves a value to database.

Parameters

Parameter name Required Type Description
hContact Yes number Contact number or nil.
module Yes string Module name.
setting Yes string Setting name.
value Yes boolean, number, string, table (array of bytes) Setting value.
type No number Type of setting. Takes values:
  • 1 = DBVT_BYTE
  • 2 = DBVT_WORD
  • 4 = DBVT_DWORD
  • 252 = DBVT_WCHAR
  • 253 = DBVT_UTF8
  • 254 = DBVT_BLOB
  • 255 = DBVT_ASCIIZ

Result

     Type: boolean

     Returns true on success, otherwise false.

Example

db.WriteSetting(nil, 'test', 'some', true)


DeleteSetting

Deletes a setting.

Parameters

Parameter name Required Type Description
hContact Yes number Contact number or nil.
module Yes string Module name.
setting Yes string Setting name.

Result

     Type: boolean

     Returns true on success, otherwise false.

Example

db.DeleteSetting(nil, 'test', 'some')


DeleteModule

Deletes a module (group of settings).

Parameters

Parameter name Required Type Description
hContact Yes number Contact number or nil.
module Yes string Module name.

Result

     Type: boolean

     Returns true on success, otherwise false.

Example

db.DeleteModule(nil, 'test')