Recent Changes - Search:

add Table DB page

hide Table DB

Table DB


hide Topics

Topics

show Changed

Changed

Visitor's book Site map pmwiki-2.3.37

Table DB Design Notes

Initial requirements: Webteam/TableDB(approve sites)


June 27, 2009 - JB

I created a usage manual since I was forgetting how to use the markup myself.

http://gnuzoo.org/tabledb/Site/UsageManual(approve sites)

The sqlite database routines have been written.

ToDo:

put the tables from memory into the sqlite database (which is also memory based)

establish sqlite-like attrbutes that will be added to the tabledb markup

  • query - action
  • select
  • join
  • getrow?

The sqlite database requires that I create tables. The tables must have a name. I can make each table name a single entity based on the pagename and the table number and the anchor


April 19, 2009 - JB

After PHP gets upgraded to the newest version we have a great advantage. PHP 5 has SQLite database engine built into it. That means we can run real SQL queries on table data after it is read into memory. With SQLite we do not have to use any database, we can do it all in memory. There will not even be a file on the hard disk for the database. This is clearly the best way to get this working.

The PMWiki page source query information will go through a 'filter' that I will write in PHP that will make sure the system is safe from things like SQL injection attacks.

I already have the table data in a memory structure so putting it into the SQLite memory tables will be easy, we can then run real SQL queries, that would be able to do anything in SQL that my filters would allow - including joins as complicated as you would please! My filters will also make the syntax easier to use.


Oct 11, 2008 - JB

I felt like documenting the way TableDB stores Tables in memory global $TDBTables;

$TDBTables[$PageName][<Table Number>] = <num>
$TDBTables[$PageName][<Table Number>]['TableType'] = <data>
$TDBTables[$PageName][<Table Number>]['TableAnchor'] = <data>
$TDBTables[$PageName][<Table Number>]['Rows'] = <num>
$TDBTables[$PageName][<Table Number>]['Cols'] = <num>

$TDBTables[$PageName][<Table Number>]['TableItemType'][<num>] = <data>
$TDBTables[$PageName][<Table Number>]['TableItemAttr'][<num>] = <data>
$TDBTables[$PageName][<Table Number>]['TableItemData'][<num>] = <data>

$TDBTables[$PageName][<Table Number>]['TableItemRow'][<num>] = <num>
$TDBTables[$PageName][<Table Number>]['TableItemCol'][<num>] = <num>

  • $TDBTables[$PageName][<Table Number>]['TableType']
    • 'Pipe'
    • 'Directive'
  • $TDBTables[$PageName][<Table Number>]['TableAnchor']
    • <anchorname>
  • $TDBTables[$PageName][<Table Number>]['TableItemType'][<num>]
    • 'table'
    • 'row'
    • 'span'
    • 'head'
    • 'cell'
    • 'cellnr'
    • 'caption'
    • 'tableend'
  • $TDBTables[$PageName][<Table Number>]['TableItemAttr'][<num>]
    • <attributes>
  • $TDBTables[$PageName][<Table Number>]['TableItemData'][<num>]
    • <text>

May 10, 2007 - JB

http://gnuzoo.org/tabledb/Test4(approve sites)

The link above shows that tables can be read into the table array and written back out to pmwiki.


May 5, 2007 - SED

Just a question, does PmWiki have a function that reads tables already that we could utilise, perhaps if PM exposed it as an API that could be used for recipe writers?

Similary for generating a table?
  • happy if tables are always writte out with table directives
  • not that for piped tables the final || is optional, and if there is a final || trailing spaces are ignored

May 4, 2007 - JB

Analysis

I am finding myself confused by the structure of the data I am storing inside "the array" It happened upon my thoughts today that I need to have a single unified way of storing information for both table types. A new intermediate structure will make it easier to get and store table data and to extract data from it. Then routines which just want to get data can connect to this table data structure to extract data into their own structure. This will be better than going straight from page source because there is one single structure instead of two table types in page source.

Pipe Tables

Pipe tables do not have to start with table attributes ("|| attributes"), they can start with caption or head or cell. If a new pipe table does not have table attributes but a previously defined pipe table on the same page did have them, new table will assume the same attributes.

The beginning of a pipe table is determined by "||" at the start of a line that is at the top of the code or that is following a line that does not start with "||".

The end of a pipe table is determined by a line that does not start with "||".

Table attributes ("|| attributes") do not create a table but just set a variable that is what a table will use for attributes if it contains a caption, a head cell or cell.

A caption line by itself will define a table, but it will not have any rows or cells.

A row is designated by a newline between head or cell lines

Caption, Head, and Cells can be all one one line.

Table Directives

Table directives require "(:table:)" and "(:tableend:)" They do not require (:cell:) or (:cellnr:) although nothing will be output if there is not at least one of them. The first row will automatically be inserted if starting with (:cell:)

Data Structures

Table Infomation Structure

Stores table information and make it easier to redisplay and extract data.

  • Tables
    • PageName
      • Anchor (optional)
        • TableNumber (optional - default=1, from anchor if anchor specified)
          • TableType - "Pipe Table" or "Table Directives"
          • Type
          • Attr
          • Data

Table Elements

  • Pipe Table (includes at least one of the following)
    • Table Attributes (optional - does not actually create table)
    • Caption (optional)
    • Head (optional)
    • Cell (optional)
    • ROW (derived from newline)
    • TABLEEND (derived from newline not beginning with "||")
  • Table Directives
    • Table
      • Table Attributes
    • Cell
      • Cell Attributes
      • Cell Data
    • CellNR
      • CellNR Attributes
      • CellNR Data
    • TableEnd

Variable Definition Structure

Store table data in array so order of occurence of items are preserved

TableType

$Tables[$pagename][$anchor][$tablenumber]['TableType']

'PipeTable' or 'TableDirective'

Type

$Tables[$pagename][$anchor][$tablenumber]['Type']

Pipe Tables - 'ptable', 'pcaption', 'phead', 'pcell', 'prow', 'ptableend'
Table Directives - 'table', 'cellnr', 'cell', 'tableend'

Attr

$Tables[$pagename][$anchor][$tablenumber]['Attr']

Pipe Tables - ptable, pcaption, phead, pcell
Table Directives - table, cellnr, cell

Data

$Tables[$pagename][$anchor][$tablenumber]['Data']

Pipe Tables - pcaption, phead, pcell - attribute whitepsace removed
Table Directives - cellnr, cell

Memory Buffer

For a memory buffer table data will be simplified

$TableData[$tablenumber][$rownum][$colnum] = $data;

May 3, 2007 - JB

Page Test1 shows a table directives table being read and being displayed with table directives.

Page Test2 shows an ordinary table being read and it is displayed with table directives!

I did not get into processing colspan yet.

I need to add a table type to the array so I can write a table out the same way I read it in.

We need a set of default table attributes - that would be used for when a new table is created or perhaps when we are only a smaller displaying part of a table.

  • (:tabledb defaulttableattributes="border=1 class=zebra":)

May 2, 2007 - JB

Currently the recipe markup syntax is (is being) setup with table input/output syntax. This will be used in the core of the recipe. Later when SQL-like syntax is developed these markups/commands might only be used internally. Suggestion: could also develop a second markup syntax such as "(:tabledbsql select from=, where= etc...:)"?

  • Table Input/Output Markup Syntax
    • (:tabledb action=read page=page table=2 row=3 column=1:)
    • Actions
      • read - reads tables from page into array
        • page - required
        • anchor - optional - where to start looking with 'table' attribute
        • table - optional - tablenumber - default is all
        • row - optional - row number - default is all
        • column - optional - column number - default is all
      • clear - clear the array
        • page - optional - default is entire array
        • anchor - optional - where to start looking with 'table' attribute
        • table - optional - tablenumber - default is all
        • row - optional - row number - default is all
        • column - optional - column number - default is all
      • get - get values in array
        • page - optional - default is entire array
        • anchor - optional - where to start looking with 'table' attribute
        • table - optional - tablenumber - default is all
        • row - optional - row number - default is all
        • column - optional - column number - default is all
      • set - set values in array
        • page - optional - default is entire array
        • anchor - optional - where to start looking with 'table' attribute
        • table - optional - tablenumber - default is all
        • row - optional - row number - default is all
        • column - optional - column number - default is all
      • display - displays table from the array
        • page - optional - default is entire array
        • anchor - optional - where to start looking with 'table' attribute
        • table - optional - tablenumber - default is all
        • row - optional - row number - default is all
        • column - optional - column number - default is all
      • write - table to a page from array
        • writepage - required - page to write to
        • page - required - array reference
        • anchor - optional - where to start looking with 'table' attribute
        • table - optional - tablenumber - default is all
        • row - optional - row number - default is all
        • column - optional - column number - default is all

April 30, 2007

  • !Define array setup:
    • Array TableDB([pagename][tablenumber][rownumber][cellnumber]
      • tablename - dynamically created - suggest 'table1', 'table2', 'table3', etc.
      • Header cells can be ignored or included, but treated like an ordinary cell so when, the PHP function will receive a pagename and then true or false to include headers cells.
      good point
      • what should be done with captions?
      captions in source tables can be ignored initially
  • !Table Types
    happy to accept this initially if it means getting something working quicker
    one source of tables is Fixture Card/May(approve sites), but it is currently in piped table format
    the other source of tables (club night(approve sites) - an archaic perl back end script, the initial reason for this project) will be replaced by TTC/Club Night(approve sites) - a table is mocked up there now, see also ReadTable3, ReadTable4, and ReadTable5
  • Markup
    • I can read from tables using "tabledb Markup" - like (:tabledb from="Main.ReadTable1":) example is at page ReadTest1?.
    • parameters to allow
      • from - pagename
      • tablenumber (in order as appears on the page)
      • column number (a single number or a range like "1-5")
      • row number (a single number or a range like "3-5")
      • etc
    • markup questions
      • will we allow wildcards later, eg from=FixtureCard2007*, column=5-
      • will we allow multiple selections later, eg from=FixtureCard/Jan,FixtureCard/Feb

tahi Page last modified on 2016 Jul 26 19:12

Edit - History - Recent Changes - WikiHelp - Search - email page as link -> mailto:?Subject="KiwiWiki: Table DB Design Notes"&Body=