©2003 Hal Helms, Inc. Variables The Tao that can be told is not the eternal Tao. The name that can be named is no t the eternal Name. —Lao-Tzu.

Slides:



Advertisements
Similar presentations
Arrays.
Advertisements

1 Array Seree Chinodom Department of Computer Science.
Chapter 31 Basic Form-Processing Techniques JavaServer Pages By Xue Bai.
Objectives Using functions to organize PHP code
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Lecture-5 Though SQL is the natural language of the DBA, it suffers from various inherent disadvantages, when used as a conventional programming language.
Week 5 IBS 520. ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own.
Variables and Conditionals Hal Helms halhelms.com.
Basics of ASP.NET. 2 © UW Business School, University of Washington 2004 Outline Installing ASP.NET and Web Matrix Data Types Branching Structure Procedures.
Fast Track to ColdFusion 9. Getting Started with ColdFusion Understanding Dynamic Web Pages ColdFusion Benchmark Introducing the ColdFusion Language Introducing.
Chapter 2: Introduction to C++.
ASP.NET Programming with C# and SQL Server First Edition
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
Web forms in PHP Forms Recap  Way of allowing user interaction  Allows users to input data that can then be processed by a program / stored in a back-end.
Chapter 4 – The Building Blocks Data Types Literals Variables Constants.
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
Chapter 5 Java Script And Forms JavaScript, Third Edition.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
CSCI 6962: Server-side Design and Programming JDBC Database Programming.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
JavaScript, Fourth Edition
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
CSC 2720 Building Web Applications HTML Forms. Introduction  HTML forms are used to collect user input.  The collected input is typically sent to a.
Chapter 8 Cookies And Security JavaScript, Third Edition.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Using Client-Side Scripts to Enhance Web Applications 1.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Arrays.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Chapter 8: Arrays.
Website Development with PHP and MySQL Saving Data.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
XHTML & Forms. PHP and the WWW PHP and HTML forms – Forms are the main way users can interact with your PHP scrip Typical usage of the form tag in HTML.
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
Basic Data Types Numbers (integer and floating point)‏ Strings (sequences of characters)‏ Boolean values (true/false)‏
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
Using Derrick Rapley Maryland CFUG January 8, 2002.
JAVA BEANS JSP - Standard Tag Library (JSTL) JAVA Enterprise Edition.
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
 2001 Prentice Hall, Inc. All rights reserved. Chapter 7 - Introduction to Common Gateway Interface (CGI) Outline 7.1Introduction 7.2A Simple HTTP Transaction.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
Java Software Solutions Lewis and Loftus Chapter 6 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Objects for Organizing Data.
Creating Forms on a Web Page. 2 Introduction  Forms allow Web developers to collect visitor feedback  Forms create an environment that invites people.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Visual C# 2005 Using Arrays. Visual C# Objectives Declare an array and assign values to array elements Initialize an array Use subscripts to access.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Using Structures With CFCs By Selene Bainum. June 27 th - 30 th 2007www.cfunited.com Why Am I here? Familiar with structures Familiar with ColdFusion.
CGS 3066: Web Programming and Design Spring 2016 PHP.
Web Database Programming Using PHP
Information and Computer Sciences University of Hawaii, Manoa
Web Database Programming Using PHP
Variables and Conditions Nicholas Tunney Senior Software Architect
JavaScript: Functions.
ISC440: Web Programming 2 Server-side Scripting PHP 3
Arrays We often want to organize objects or primitive data in a way that makes them easy to access and change. An array is simple but powerful way to.
PHP.
Web DB Programming: PHP
JavaScript: Introduction to Scripting
PHP an introduction.
Presentation transcript:

©2003 Hal Helms, Inc. Variables The Tao that can be told is not the eternal Tao. The name that can be named is no t the eternal Name. —Lao-Tzu

©2003 Hal Helms, Inc. ColdFusion MX Foundations 2 Data types  Variables have a property called a data type that specifies t he type of data that a variable holds –integer –string –decimal number –boolean value –record set ds

©2003 Hal Helms, Inc. ColdFusion MX Foundations 3 Strong typing  Some languages require that you declare a variable's data type prior to using it –String state = "Indiana"; // Java  Once declared, a variable's data type cannot change –boolean state = true; // illegal!! –Such languages are called strongly-typed ds

©2003 Hal Helms, Inc. ColdFusion MX Foundations 4 Strong typing: pros & cons  Pros –allows compiler (most strongly-typed languages are also compiled languages) to optimize performance –enforced rigor helpful when dealing with large-scale or complex applications  Cons –slower development

©2003 Hal Helms, Inc. ColdFusion MX Foundations 5 Weak typing  Other languages do not require that you declare a variable' s data type prior to using it  Data types can change  Such languages are called weakly-typed ds

©2003 Hal Helms, Inc. ColdFusion MX Foundations 6 Weak typing: pros and cons  Pros –no compile cycle (most weakly typed languages are interpreted languages)  Cons –easier to make mistakes in overwriting variables –slower execution since all data typing must be done at run time –harder to maintain code

©2003 Hal Helms, Inc. ColdFusion MX Foundations 7 Compiled languages  Some languages have a separate compile cycle during whi ch several checks are made including checking variables are f or valid types, correct naming and scoping of variables, etc. –Java –C#  After the compile cycle is completed, the program can be r un  When the program runs, we are said to be in run time

©2003 Hal Helms, Inc. ColdFusion MX Foundations 8 Interpreted languages  Some languages have no separate compile cycle but inste ad do all checking at run time –ColdFusion –Smalltalk

©2003 Hal Helms, Inc. ColdFusion MX Foundations 9 ColdFusion?  ColdFusion is… –weakly-typed –interpreted

©2003 Hal Helms, Inc. ColdFusion MX Foundations 10 Data types can be simple…  String ‘Welcome to Programming Foundations’  Numeric  Date {ts ' :45:43'}  Boolean TRUE FALSE ds

©2003 Hal Helms, Inc. ColdFusion MX Foundations 11 …or complex  Structure – collection of name/value pairs  Array – numbered collection of other data types (not name/value pairs)  Query result set – return by a  List – Pat, Wesley, Donna, Kathy, Michael, Jim ds

©2003 Hal Helms, Inc. ColdFusion MX Foundations 12 More on variables  Variables have two important properties –scope: where the variable can be accessed from –lifespan (or span): how long the variable lives

©2003 Hal Helms, Inc. ColdFusion MX Foundations 13 Scopes in ColdFusion  Variables that can be seen by the page that called them as well (including d files) are called local variables  Variables that can be seen by all pages (including custom t ags and d files) are called global variables ds

©2003 Hal Helms, Inc. ColdFusion MX Foundations 14 Lifespans in ColdFusion  Most variables live only for a single page request  Those that live across multiple page requests are called persistent Client Web server ColdFusion server Database server

©2003 Hal Helms, Inc. ColdFusion MX Foundations 15 Variable matrix ScopeSpan variables localpage request request globalpage request form globalpage request URL globalpage request attributes localpage request caller localpage request CGI globalpage request cookie globalpersistent session globalpersistent client globalpersistent application globalpersistent server globalpersistent ds

©2003 Hal Helms, Inc. ColdFusion MX Foundations 16 Creating/setting a variable  Method 1 (common)  Method 2 ds

©2003 Hal Helms, Inc. ColdFusion MX Foundations 17 Local scope examples * *Unscoped variables are part of the default “variables” local scope ds

©2003 Hal Helms, Inc. ColdFusion MX Foundations 18 Specifying different scopes same

©2003 Hal Helms, Inc. ColdFusion MX Foundations 19 Form variables  When a form is submitted through the post method, any f orm fields are placed into the form scope of the form processo r (the page set in the form's action property) and can be accessed by that page <input type="hidden" name="today" value="Monday"> …

©2003 Hal Helms, Inc. ColdFusion MX Foundations 20 URL variables  You can pass variables on a URL in a query string  The query string is created by appending a ? to the URL and then adding name=value pairs separated by an ampersan d  These variables are then accessible to the called page in the URL scope

©2003 Hal Helms, Inc. ColdFusion MX Foundations 21 Displaying variables  Wrap pound signs around a variable and set within tags Hello, there, #yourName#  You don't need to do this within CF tags and functions (usu ally)

©2003 Hal Helms, Inc. ColdFusion MX Foundations 22 The Evaluate() function  Use it when you want to force an evaluation of a name as a variable.  Example: –When you submit a form to a processing page, you get a variable called form.fieldlist, a list of the form fields…

©2003 Hal Helms, Inc. ColdFusion MX Foundations 23 Evaluate() #aFormField#  What will this produce?

©2003 Hal Helms, Inc. ColdFusion MX Foundations 24 Evaluate() #Evaluate(‘form.’ & aFormField)#  What will this produce?

©2003 Hal Helms, Inc. Complex Variables A child of five would understand this. Send someone to fetch a child of five. —Groucho Marx

©2003 Hal Helms, Inc. ColdFusion MX Foundations 26 Complex data types in ColdFusio n  Structure –collection of name/value pairs  Array –numbered collection of data  Query result set –return by a  List –series of tokens and delimiters  Bob,Sue,Frank,Anne  21|257|TRUE|c:\cfusionmx\wwwroot\test

©2003 Hal Helms, Inc. ColdFusion MX Foundations 27 What is a structure?  Set of name/value pairs that all relate to a central topic or idea ISBN titleA Prayer for Owen Meany authorJohn Irving publisherBallantine Books formatPaperback price14.00

©2003 Hal Helms, Inc. ColdFusion MX Foundations 28 Why structures?  Organizes related data into a single variable that is sim pler to store and manipulate  Provides data encapsulation

©2003 Hal Helms, Inc. ColdFusion MX Foundations 29 Working with structures 1. aStructure.author  John Irving valuestructure-name ISBN titleA Prayer for Owen Meany authorJohn Irving publisherBallantine Books formatPaperback price aStructure[‘author’]  John Irving keysvalues key

©2003 Hal Helms, Inc. ColdFusion MX Foundations 30 Structure limitations  Structures can hold as values… –simple values –arrays –structures –result sets –lists

©2003 Hal Helms, Inc. ColdFusion MX Foundations 31 Create a structure Method 1

©2003 Hal Helms, Inc. ColdFusion MX Foundations 32 Create a structure Method 2

©2003 Hal Helms, Inc. ColdFusion MX Foundations 33 Loop over a structure Method 1 #aProperty# is set to a #aBook[aProperty]#

©2003 Hal Helms, Inc. ColdFusion MX Foundations 34 Loop over a structure Method 2 #aProperty# is set to a #Evaluate('aBook.' & aProperty)#

©2003 Hal Helms, Inc. ColdFusion MX Foundations 35 By value  With most variables, a duplicate assignment creates a cop y of the value in a memory location  Changes to greeting will not affect myGreeting "Hello" greeting "Hello" myGreeting

©2003 Hal Helms, Inc. ColdFusion MX Foundations 36 By reference  With structures only, a duplicate assignment creates a poin ter to the same memory location  Changes to book will affect myBook structure book myGreet ing

©2003 Hal Helms, Inc. ColdFusion MX Foundations 37 What will Pavorotti be singing? Today, Mr. Pavarotti will perform "#concertChoice.work#"

©2003 Hal Helms, Inc. ColdFusion MX Foundations 38 Use Duplicate() for by value copie s Today, Mr. Pavarotti will perform "#concertChoice.work#"

©2003 Hal Helms, Inc. ColdFusion MX Foundations 39 Structure functions Duplicate() IsStruct() StructClear() StructCount() StructDelete() StructFind() StructInsert() StructIsEmpty() StructKeyArray() StructKeyExists() StructKeyList() StructNew() StructUpdate()

©2003 Hal Helms, Inc. ColdFusion MX Foundations 40 Duplicate() newBook.price  ISBN titleA Prayer for Owen Meany authorJohn Irving publisherBallantine Books formatPaperback price14.00 Book: a structure

©2003 Hal Helms, Inc. ColdFusion MX Foundations 41 IsStruct() IsStruct(Book)  TRUE IsStruct(FBrocks)  FALSE ISBN titleA Prayer for Owen Meany authorJohn Irving publisherBallantine Books formatPaperback price14.00 Book: a structure

©2003 Hal Helms, Inc. ColdFusion MX Foundations 42 StructClear() StructClear(Book) IsStruct(Book)  TRUE Book.title  error ISBN titleA Prayer for Owen Meany authorJohn Irving publisherBallantine Books formatPaperback price14.00 Book: a structure

©2003 Hal Helms, Inc. ColdFusion MX Foundations 43 StructCount() StructCount(Book)  6 ISBN titleA Prayer for Owen Meany authorJohn Irving publisherBallantine Books formatPaperback price14.00 Book: a structure

©2003 Hal Helms, Inc. ColdFusion MX Foundations 44 StructDelete() StructDelete(Book,‘title’)  ISBN authorJohn Irving publisherBallantine Books formatPaperback price14.00 ISBN titleA Prayer for Owen Meany authorJohn Irving publisherBallantine Books formatPaperback price14.00 Book: a structure

©2003 Hal Helms, Inc. ColdFusion MX Foundations 45 StructFind() StructFind(Book,‘title’)  A Prayer for Owen Meany StructFind(Book,‘reserved’)  error ISBN titleA Prayer for Owen Meany authorJohn Irving publisherBallantine Books formatPaperback price14.00 Book: a structure

©2003 Hal Helms, Inc. ColdFusion MX Foundations 46 StructInsert() StructInsert(Book,‘reserved’,4)  (The fourth parameter for this function, “allowoverwrite” is optional and defaults to FALSE. This option determines whether StructInsert() should overwrite the value of an existing key value.) ISBN titleA Prayer for Owen Meany authorJohn Irving publisherBallantine Books formatPaperback price14.00 reserved4 ISBN titleA Prayer for Owen Meany authorJohn Irving publisherBallantine Books formatPaperback price14.00 Book: a structure

©2003 Hal Helms, Inc. ColdFusion MX Foundations 47 StructIsEmpty() StructIsEmpty(Book)  FALSE StructIsEmpty(CD)  error ISBN titleA Prayer for Owen Meany authorJohn Irving publisherBallantine Books formatPaperback price14.00 Book: a structure

©2003 Hal Helms, Inc. ColdFusion MX Foundations 48 StructKeyArray() StructKeyArray(Book)  ISBNAUTHORFORMATPUBLISHERTITLEPRICE ISBN titleA Prayer for Owen Meany authorJohn Irving publisherBallantine Books formatPaperback price14.00 Book: a structure

©2003 Hal Helms, Inc. ColdFusion MX Foundations 49 StructKeyExists() StructKeyExists(Book,‘title’)  TRUE StructKeyExists(Book,‘reserved’)  FALSE StructKeyExists(Z,‘title’)  error ISBN titleA Prayer for Owen Meany authorJohn Irving publisherBallantine Books formatPaperback price14.00 Book: a structure

©2003 Hal Helms, Inc. ColdFusion MX Foundations 50 StructKeyList() StructKeyList(Book)  “AUTHOR,ISBN,FORMAT,PRICE,PUBLISHER,TITLE” ISBN titleA Prayer for Owen Meany authorJohn Irving publisherBallantine Books formatPaperback price14.00 Book: a structure

©2003 Hal Helms, Inc. ColdFusion MX Foundations 51 StructNew() StructIsEmpty(Book)  TRUE IsStruct(Book)  TRUE ISBN titleA Prayer for Owen Meany authorJohn Irving publisherBallantine Books formatPaperback price14.00 Book: a structure

©2003 Hal Helms, Inc. ColdFusion MX Foundations 52 StructUpdate() StructUpdate(Book,‘price’,16.95)  ISBN titleA Prayer for Owen Meany authorJohn Irving publisherBallantine Books formatPaperback price16.95 ISBN titleA Prayer for Owen Meany authorJohn Irving publisherBallantine Books formatPaperback price14.00 Book: a structure

©2003 Hal Helms, Inc. ColdFusion MX Foundations 53 Arrays  Definition: a numbered (or indexed) set of values in 1 t o 3 dimensions

©2003 Hal Helms, Inc. ColdFusion MX Foundations 54 Array limitations  Arrays can hold as values… –simple values –arrays –structures –result sets –lists

©2003 Hal Helms, Inc. ColdFusion MX Foundations 55 1-D Arrays  Think of as a single row in a spreadsheet [1][2][3][4]

©2003 Hal Helms, Inc. ColdFusion MX Foundations 56 2-D Arrays  Think of as multiple rows in a spreadsheet [1][2][3][4] [1] [2] [3]

©2003 Hal Helms, Inc. ColdFusion MX Foundations 57 3-D Arrays  Think of as a spreadsheet cube [1][2][3][4] [1] [2] [3] [1] [2] [3]

©2003 Hal Helms, Inc. ColdFusion MX Foundations 58 Refer to array elements  Use the array name followed by the proper index/es in square brackets [1][2][3][4] onedee onedee[3]  [1][2][3][4] [1] [2] [3] twodee twodee[3][4]  64

©2003 Hal Helms, Inc. ColdFusion MX Foundations 59 Create a 1-D array onedee

©2003 Hal Helms, Inc. ColdFusion MX Foundations 60 Loop over 1-D array <cfloop from="1" to="#ArrayLen(aCart)#" index="aCol"> #aCart[aCol]#

©2003 Hal Helms, Inc. ColdFusion MX Foundations 61 Create a 2-D array twodee

©2003 Hal Helms, Inc. ColdFusion MX Foundations 62 Loop over 2-D array <cfloop from="1" to="#ArrayLen(aCart)#" index="aRow"> <cfloop from="1" to="#ArrayLen(aCart[aRow])#" index="aCol"> #aCart[aRow][aCol]#

©2003 Hal Helms, Inc. ColdFusion MX Foundations 63 Unbalanced arrays  Arrays can be “unbalanced”—meaning the number of columns may vary from row to row.  This is a valid CF array: CF 1 Just for fun, write a loop that produces this array…

©2003 Hal Helms, Inc. ColdFusion MX Foundations 64 Things to look out for  It is easy to “walk off” the end of an array—especially unbalanced arrays.  Make sure the array index exists—or CF will throw an error myArr

©2003 Hal Helms, Inc. ColdFusion MX Foundations 65 Array functions ArrayAppend() ArrayAvg() ArrayClear() ArrayDeleteAt() ArrayIsEmpty() ArrayLen() ArrayMax() ArrayMin() ArrayNew() ArrayPrepend() ArraySet() ArraySort() ArraySum() ArraySwap() ArrayToList()

©2003 Hal Helms, Inc. ColdFusion MX Foundations 66 Use array functions on 2-D arrays  Made to work on 1-D arrays  2-D arrays can be thought of as a series of stacked 1-D arrays stacked 1-D arrays single 2-D array

©2003 Hal Helms, Inc. ColdFusion MX Foundations 67 Use array functions on 2-D arrays  If you want to use array functions on 2-D arrays, point at o ne of the stacked 1-D arrays by specifying which row you wan t the function to operate on  Example #ArraySum(twodee[3])#

©2003 Hal Helms, Inc. ColdFusion MX Foundations 68 ArrayAppend() A: 1-D array B: 2-D array ArrayAppend(A,‘x’)  ArrayAppend(B,‘x’)  ERROR ArrayAppend(B[2],‘x’)  x x

©2003 Hal Helms, Inc. ColdFusion MX Foundations 69 ArrayAvg() ArrayAvg(A)  2.5 ArrayAvg(B)  ERROR ArrayAvg(B[2])  5 A: 1-D array B: 2-D array

©2003 Hal Helms, Inc. ColdFusion MX Foundations 70 ArrayClear() ArrayClear(A)  YES ArrayIsEmpty(A)  YES ArrayClear(B)  YES ArrayIsEmpty(B)  YES ArrayClear(B[2])  YES ArrayIsEmpty(B[2])  YES ArrayIsEmpty(B[3])  NO A: 1-D array B: 2-D array

©2003 Hal Helms, Inc. ColdFusion MX Foundations 71 ArrayDeleteAt() ArrayDeleteAt(A,2)  ArrayDeleteAt(B,2)  ArrayDeleteAt(B[2],2)  A: 1-D array B: 2-D array

©2003 Hal Helms, Inc. ColdFusion MX Foundations 72 ArrayInsertAt() ArrayInsertAt(A,3,‘x’)  ArrayInsertAt(B,2,‘x’)  ERROR ArrayInsertAt(B[2],2,‘x’)  A: 1-D array B: 2-D array x x

©2003 Hal Helms, Inc. ColdFusion MX Foundations 73 ArrayIsEmpty() See ArrayClear() function A: 1-D array B: 2-D array

©2003 Hal Helms, Inc. ColdFusion MX Foundations 74 ArrayMax() ArrayMax( A )  4 ArrayMax( B )  ERROR ArrayMax( B[2] )  8 A: 1-D array B: 2-D array

©2003 Hal Helms, Inc. ColdFusion MX Foundations 75 ArrayMin() ArrayMin(A)  1 ArrayMin(B)  ERROR ArrayMin(B[2])  2 A: 1-D array B: 2-D array

©2003 Hal Helms, Inc. ColdFusion MX Foundations 76 ArrayNew() A: 1-D array B: 2-D array

©2003 Hal Helms, Inc. ColdFusion MX Foundations 77 ArrayPrepend() ArrayPrepend(A,‘x’)  ArrayPrepend(B,‘x’)  ERROR ArrayPrepend(B[2],‘x’)  A: 1-D array B: 2-D array x x

©2003 Hal Helms, Inc. ColdFusion MX Foundations 78 ArrayResize() Resets an array to a specified minimum number. Used for performance gains on very large arrays

©2003 Hal Helms, Inc. ColdFusion MX Foundations 79 ArraySet()   ERROR  A: 1-D array B: 2-D array

©2003 Hal Helms, Inc. ColdFusion MX Foundations 80 ArraySort() ArraySort(A,‘numeric’,‘desc')  ArraySort(B,‘numeric,‘desc’)  ERROR ArraySort(B[2],‘numeric,‘desc’)  A: 1-D array B: 2-D array

©2003 Hal Helms, Inc. ColdFusion MX Foundations 81 ArraySum() ArraySum(A)  10 ArraySum(B)  ERROR ArraySum(B[2])  20 A: 1-D array B: 2-D array

©2003 Hal Helms, Inc. ColdFusion MX Foundations 82 ArraySwap() ArraySwap(A,3,2)  ArraySwap(B,3,2)  ArraySum(B[2],3,2)  A: 1-D array B: 2-D array

©2003 Hal Helms, Inc. ColdFusion MX Foundations 83 ArrayToList() ArrayToList(A)  “1,2,3,4” ArrayToList(B)  error ArrayToList(B[2],‘|’)  “2|4|6|8” A: 1-D array B: 2-D array

©2003 Hal Helms, Inc. ColdFusion MX Foundations 84 Lists  Definition: a list is a string consisting of meaningful data (or tokens) separated by delimiters

©2003 Hal Helms, Inc. ColdFusion MX Foundations 85 Unlimited delimiters  Delimiters can be any single byte character a,b,c (comma is default delimiter) a|b|c myPage.cfm?a=1&b=17552&c=TRUE a b c a b c

©2003 Hal Helms, Inc. ColdFusion MX Foundations 86 List limitations  Lists can hold as values… –simple values –lists

©2003 Hal Helms, Inc. ColdFusion MX Foundations 87 Read a value from a list ListGetAt('a,b,c',2)  b

©2003 Hal Helms, Inc. ColdFusion MX Foundations 88 See if a value exists in a list ListFind(myList,2)  TRUE | FALSE ListFindNoCase(myList,2)  TRUE | FALSE

©2003 Hal Helms, Inc. ColdFusion MX Foundations 89 Set the value of a list element

©2003 Hal Helms, Inc. ColdFusion MX Foundations 90 Insert an element into a list

©2003 Hal Helms, Inc. ColdFusion MX Foundations 91 Delete an element from a list

©2003 Hal Helms, Inc. ColdFusion MX Foundations 92 Loop over a list #aListElement#

©2003 Hal Helms, Inc. ColdFusion MX Foundations 93 List functions ListLen() ListPrepend() ListQualify() ListRest() ListSetAt() ListSort() ListToArray() ListValueCount() ListValueCountNoCase() ListAppend() ListChangeDelims() ListContains() ListContainsNoCase() ListDeleteAt() ListFind() ListFindNoCase() ListFirst() ListGetAt() ListInsertAt() ListLast()

©2003 Hal Helms, Inc. ColdFusion MX Foundations 94 ListAppend() myNums  25,50,75 myNums  25,50,75,100

©2003 Hal Helms, Inc. ColdFusion MX Foundations 95 ListChangeDelims() myNums  25,50,75 myNums 

©2003 Hal Helms, Inc. ColdFusion MX Foundations 96 ListContains() myWords  apple,baker,charlie ListContains(myWords,'BAKER',',')  0

©2003 Hal Helms, Inc. ColdFusion MX Foundations 97 ListContainsNoCase() myWords  apple,baker,charlie ListContainsNoCase(myWords,'BAKER',',')  2 ListContainsNoCase(myWords,'bak')  2 If you want to find elements (as opposed to sub-strings), use the ListFind() and ListFindNoCase() functions

©2003 Hal Helms, Inc. ColdFusion MX Foundations 98 ListDeleteAt() myNums  25,50,75 myNums  25,75

©2003 Hal Helms, Inc. ColdFusion MX Foundations 99 ListFind() myWords  apple,baker,charlie ListFind(myWords,'BAKER',',')  0 ListFind(myWords,'baker',',')  2 ListFind(myWords,'bak',',')  0

©2003 Hal Helms, Inc. ColdFusion MX Foundations 100 ListFindNoCase() myWords  apple,baker,charlie ListFind(myWords,'BAKER',',')  2 ListFind(myWords,'baker',',')  2 ListFind(myWords,'bak',',')  0

©2003 Hal Helms, Inc. ColdFusion MX Foundations 101 ListFirst() myWords  apple,baker,charlie ListFirst(myWords)  apple

©2003 Hal Helms, Inc. ColdFusion MX Foundations 102 ListGetAt() myWords  apple,baker,charlie ListGetAt(myWords,3)  charlie

©2003 Hal Helms, Inc. ColdFusion MX Foundations 103 ListInsertAt() myNums  25,50,75 myNums  25,37,50,75

©2003 Hal Helms, Inc. ColdFusion MX Foundations 104 ListLast() myWords  apple,baker,charlie ListLast(myWords,',')  charlie

©2003 Hal Helms, Inc. ColdFusion MX Foundations 105 ListLen() myWords  apple,baker,charlie ListLen(myWords,',')  3

©2003 Hal Helms, Inc. ColdFusion MX Foundations 106 ListPrepend() myNums  25,50,75 myNums  12,25,50,75

©2003 Hal Helms, Inc. ColdFusion MX Foundations 107 ListQualify() myWords  apple,baker,charlie myWords  'apple','baker','charlie'

©2003 Hal Helms, Inc. ColdFusion MX Foundations 108 ListRest() myWords  apple,baker,charlie ListRest(myWords,',')  baker,charlie

©2003 Hal Helms, Inc. ColdFusion MX Foundations 109 ListSetAt() myNums  25,50,75 myNums  25,50,100

©2003 Hal Helms, Inc. ColdFusion MX Foundations 110 ListSort() myNums  25,50,75 myNums  75,50,25 myWords  apple,baker,charlie myWords  charlie,baker, apple

©2003 Hal Helms, Inc. ColdFusion MX Foundations 111 ListToArray() myWords  apple,baker,charlie arr  applebakercharlie

©2003 Hal Helms, Inc. ColdFusion MX Foundations 112 ListValueCount() myWords  apple,baker,charlie ListValueCount(myWords,'charlie',',')  1 ListValueCount(myWords,'CHARLIE',',')  0

©2003 Hal Helms, Inc. ColdFusion MX Foundations 113 ListValueCountNoCase() myWords  apple,baker,charlie ListValueCount(myWords,'charlie',',')  1 ListValueCount(myWords,'CHARLIE',',')  1

©2003 Hal Helms, Inc. ColdFusion MX Foundations 114 Query Result Set  Definition: row(s) of values returned by an SQL query

©2003 Hal Helms, Inc. ColdFusion MX Foundations 115 Query a database …SQL Statement…

©2003 Hal Helms, Inc. ColdFusion MX Foundations 116 Query properties SELECT center_ID, name, city FROM Centers The columns returned are #myQ.columnList# I am now on row #currentRow#

©2003 Hal Helms, Inc. ColdFusion MX Foundations 117 Loop over a query  Use either | #column_name# or #column_name#

©2003 Hal Helms, Inc. ColdFusion MX Foundations 118 Get results of one column as a list  Use the ValueList() or QuotedValueList() function publishers  Techspedition,Techspedition,Prentice Hall,Addison-Wesl ey,Sams

©2003 Hal Helms, Inc. ColdFusion MX Foundations 119 Dereference a query value Your name is #UserInfo.firstName#

©2003 Hal Helms, Inc. ColdFusion MX Foundations 120 Query functions IsQuery() QueryAddColumn() QueryAddRow() QueryNew() QuerySetCell() QuotedValueList() ValueList()