0% found this document useful (0 votes)
63 views12 pages

Build Your Own DB - Part 1 - Documentos Google

This document describes how to build a basic relational database using App Inventor 2 list blocks. It introduces concepts like tables, rows, columns, and procedures for slicing and dicing tables using criteria like equality comparisons. Sample data in a table format is provided for unit conversions. Procedures are demonstrated and explained for selecting rows by column value (WHERE), getting distinct values from a column (DISTINCT), and selecting specific columns (SELECT). The goal is to work incrementally from simple lists up to relational database concepts and capabilities using App Inventor's list facilities.

Uploaded by

Josiaine Alencar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views12 pages

Build Your Own DB - Part 1 - Documentos Google

This document describes how to build a basic relational database using App Inventor 2 list blocks. It introduces concepts like tables, rows, columns, and procedures for slicing and dicing tables using criteria like equality comparisons. Sample data in a table format is provided for unit conversions. Procedures are demonstrated and explained for selecting rows by column value (WHERE), getting distinct values from a column (DISTINCT), and selecting specific columns (SELECT). The goal is to work incrementally from simple lists up to relational database concepts and capabilities using App Inventor's list facilities.

Uploaded by

Josiaine Alencar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

How to Build Your Own Data Base using Blocks Part 1

AbeGetzler
7/6/2014

Motivation
Prerequisitereading
SomeSampleData
SlicingandDicing
WHERE_EQ
WHERE_EQ_NUMBER
WHERE_EQ_TEXT
DISTINCT
SELECT
Asampleappconversions

Motivation

AppInventor2doesnotprovideaccesstoanykindoflocalSQLdatabase.ItoffersTinyDB,a
key/datalocalstore,andFusionTablesblocks,forSQLaccesstoGooglesWebbasedrelational
database.TheFusionTablesinterfacerequiresyoutorememberyourcolumnnames,andto
understandandfollowSQLsyntaxtobuildqueries.

Inthispaper,wewillworkourwayuptorelationaldatabaseconceptsbybuildingonthelist
facilitiesofAppInventor.Westartwithsomefamiliaritywithsimplelists,andworkourwayupto
tables.

Prerequisite reading

http://www.appinventorblocks.com/appinventortutorialstips/appinventorlists

Some Sample Data

Herespartofaconversiontable,doneasalistoflists,alsoknownasatable.

Toreadthis,wegorowbyrow.Thefirstrowsaysthattoworkwithlengths,wecanconvertfeet
toinchesbymultiplyingby12.Likewise,thesecondrowsaysthattoworkwithlengths,wecan
convertmilestofeetbymultiplyingby5280.

Ithrewinafewtimeconversionsalsofollowingthesamepattern.Eachcolumnservesasingle
purpose:

1. TheDimension:typeofunitsbeingconverted(length,time,weight,etc.)
2. ThemeasurebeingconvertedFrom
3. ThemeasurebeingconvertedTo
4. WhatFactorwemustmultiplybytodotheconversion.

Ivedonethisasascreenshottoshowthestructureandhowyoucannestlistsinsidelists.Ive
usedtherightclickInlineInputsandExternalInputsBlockEditoroptionstogetthisrowsand
columnseffect.YoucanalsotypedataintoaspreadsheetprogramandexportthedataasaC
SV
table:

ImgoingtocheatandusetheAppInventoremulator,rightclickDoIt,andoneofthetableblocks
toextractthedatainCSVtableformat,incaseyouwanttocopymydata...

"length","feet","inches","12"
"length","miles","feet","5280"
"length","inches","cm","2.54"
"time","hours","minutes","60"
"time","minutes","seconds","60"
"time","seconds","milliseconds","1000"
"time","milliseconds","seconds","0.001"

Slicing and Dicing

DataAnalystsuseacookinganalogyfortheactofchoppingupatablebyrowandbycolumn.
Onewaytosliceupatableistopickonlythoserowsthathaveaparticularvalueinonecolumn.
InSQLthisisspecifiedwithaWHEREclause,soletsnameourproceduresusingtheword
WHERE

WHERE_EQ

Thisisaresultprocedurethatacceptsatable(alistoflists)andreturnsasmallertablecontaining
thesamecolumns,butonlytherowswhereaparticularcolumn(specifiedbycolumnnumber)
equalsaparticularvalue.

BecauseAppInventorhastwodifferentkindsofcomparisonblocks,onefornumbersandanother
fortext,wedecideearlyonwhichcomparisonwewilluseratherthandecidingonarowbyrow
basis.Peopleusuallystoreeithernumbersortextinanyonetablecolumn,andnevermixthem.

WHERE_EQ_NUMBER

WHERE_EQ_TEXT

Noticethatthesetworeturnproceduresdifferonlyinthetypeofblockusedforthecomparisonin
theinnerifthenblock.

Forconvenience,weonlyneedtoremembertousetheWHERE_EQprocedure

HeresasampleapplicationofWHERE_EQ,usingaspinnerselectionoflengthforcolumn1of
ourdatatable,togiveusjusttherowsforlengthconversions

BecauseWHERE_EQisareturnprocedureitcanbecombinedwithotherreturnprocedurecalls.
IfwewanttoreturnjusttherowsfromoursampledatawithaDimension(column1)valueof
lengthandaFromvalueoffeetwenestthecalls

Ifwewanttotestforotherconditionssuchaslessthan,greaterthan,etc.,wecanduplicate
ourWHERE_EQprocedures,andchangethenamesandtestcriteria,suchasWHERE_LT,
WHERE_GT,etc.

DISTINCT

Ifyouwanttofilteryourtabledatabyparticularcolumnvalues,youneedaprocedurethatwill
returnalistofdistinctvaluesfromoneparticulartablecolumn.Thiscanbeusedtoprimethe
ElementslistofaListPicker,ListView,oraSpinner.

Thisbuildsandreturnsaresultlistbystartingwithanemptylist,runningthroughtheinputtable,
andcheckingeachvalueintherequestedcolumnnumberagainsttheresultlistbeforeaddingit.

ThisisanexampleoftheexpressionyouwouldusetofeedtheElementsofaSpinnerorList
Pickertodecidewhichdimension(lengthortime)tousetofilterourconversiontable...

SELECT

Thisisforwhenyouwantjustsomeofthecolumnsinatable,butalltherows

from=
atable(listoflists)input
column_nos=alistofcolumnnumbersintheinputtablewewantintheresult
result=
atablewithallfromsrows,butjusttherequestedcolumnnumbers,sliddown.

A sample app conversions

https://dl.dropboxusercontent.com/u/145520/select_where_sample1.aia
AI2gallerylink

Screen shots Designer

You might also like