Problem Solution Discussion Repeating and Editing Queries
1.12 Canceling a Partially Entered Query
1.12.1 Problem
You st art t o ent er a query, t hen decide not t o issue it aft er all.1.12.2 Solution
Cancel t he query using your line kill charact er or t he \c sequence.1.12.3 Discussion
I f you change your m ind about issuing a query t hat youre ent ering, cancel it . I f t he query is on a single line, use your line kill charact er t o erase t he ent ire line. The part icular charact er t o use depends on your t erm inal set up; for m e, t he charact er is Ct rl-U. I f youve ent ered a st at em ent over m ult iple lines, t he line kill charact er will erase only t he last line. To cancel t he st at em ent com plet ely, ent er \c and t ype Ret urn. This will ret urn you t o t he mysql prom pt : mysql SELECT - FROM limbs - ORDER BY\c mysql Som et im es \c appears t o do not hing t hat is, t he mysql prom pt does not reappear , which leads t o t he sense t hat youre t rapped in a query and cant escape. I f \c is ineffect ive, t he cause usually is t hat you began t yping a quot ed st ring and havent yet ent ered t he m at ching end quot e t hat t erm inat es t he st ring. Let m ysqls prom pt help you figure out what t o do here. I f t he prom pt has changed from mysql t o , That m eans m ysql is looking for a t erm inat ing double quot e. I f t he prom pt is inst ead, m ysql is looking for a t erm inat ing single quot e. Type t he appropriat e m at ching quot e t o end t he st ring, t hen ent er \c followed by Ret urn and you should be okay.1.13 Repeating and Editing Queries
1.13.1 Problem
The query you j ust ent ered cont ained an error, and you want t o fix it wit hout t yping t he whole t hing again. Or you want t o repeat an earlier st at em ent wit hout ret yping it .1.13.2 Solution
Use m ysqls built - in query edit or.1.13.3 Discussion
I f you issue a long query only t o find t hat it cont ains a synt ax error, what should you do? Type in t he ent ire correct ed query from scrat ch? No need. m ysql m aint ains a st at em ent hist ory and support s input - line edit ing. This allows you t o recall queries so t hat you can m odify and reissue t hem easily. There are m any, m any edit ing funct ions, but m ost people t end t o use a sm all set of com m ands for t he m aj orit y of t heir edit ing. [ 3] A basic set of useful com m ands is shown in t he following t able. Typically, you use Up Arrow t o recall t he previous line, Left Arrow and Right Arrow t o m ove around wit hin t he line, and Backspace or Delet e t o erase charact ers. To add new charact ers t o t he line, j ust m ove t he cursor t o t he appropriat e spot and t ype t hem in. When youre done edit ing, press Ret urn t o issue t he query t he cursor need not be at t he end of t he line when you do t his . [ 3] The input - line edit ing capabilit ies in m ysql are based on t he GNU Readline library. You can read t he docum ent at ion for t his library t o find out m ore about t he m any edit ing funct ions t hat are available. For m ore inform at ion, check t he Bash m anual, available online at ht t p: www.gnu.org m anual . Edit in g Ke y Effe ct of Ke y Up Arrow Scroll up t hrough st at em ent hist ory Down Arrow Scroll down t hrough st at em ent hist ory Left Arrow Move left wit hin line Right Arrow Move right wit hin line Ct r l- A Move t o beginning of line Ct r l- E Move t o end of line Backspace Delet e previous charact er Ct r l- D Delet e charact er under cursor I nput - line edit ing is useful for m ore t han j ust fixing m ist akes. You can use it t o t ry out variant form s of a query wit hout ret yping t he ent ire t hing each t im e. I t s also handy for ent ering a series of sim ilar st at em ent s. For exam ple, if you want ed t o use t he query hist ory t o issue t he series of INSERT st at em ent s shown earlier in Recipe 1.3 t o creat e t he limbs t able, first ent er t he init ial INSERT st at em ent . Then, t o issue each successive st at em ent , press t he Up Arrow key t o recall t he previous st at em ent wit h t he cursor at t he end, backspace back t hrough t he colum n values t o erase t hem , ent er t he new values, and press Ret urn. To recall a st at em ent t hat was ent ered on m ult iple lines, t he edit ing procedure is a lit t le t rickier t han for single- line st at em ent s. I n t his case, you m ust recall and reent er each successive line of t he query in order. For exam ple, if youve ent ered a t wo- line query t hat cont ains a m ist ake, press Up Arrow t wice t o recall t he first line. Make any m odificat ions necessary and press Ret urn. Then press Up Arrow t wice m ore t o recall t he second line. Modify it , press Ret urn, and t he query will execut e. Under Windows, m ysql allows st at em ent recall only for NT- based syst em s. For versions such as Windows 98 or Me, you can use t he special m ysqlc client program inst ead. However, m ysqlc requires an addit ional library file, cygwinb19.dll. I f you find a copy of t his library in t he sam e direct ory where m ysqlc is inst alled t he bin dir under t he MySQL inst allat ion direct ory , you should be all set . I f t he library is locat ed in t he MySQL lib direct ory, copy it int o your Windows syst em direct ory. The com m and looks som et hing like t his; you should m odify it t o reflect t he act ual locat ions of t he t wo direct ories on your syst em : C:\ copy C:\mysql\lib\cygwinb19.dll C:\Windows\System Aft er you m ake sure t he library is in a locat ion where m ysqlc can find it , invoke m ysqlc and it should be capable of input - line edit ing. One unfort unat e consequence of using m ysqlc is t hat it s act ually a fairly old program . For exam ple, even in MySQL 4.x dist ribut ions, m ysqlc dat es back t o 3.22.7. This m eans it doesnt underst and newer st at em ent s such as SOURCE .1.14 Using Auto-Completion for Database and Table Names
Parts
» O'Reilly-MySQL.Cookbook.eBook-iNTENSiTY. 4810KB Mar 29 2010 05:03:43 AM
» Introduction Using the mysql Client Program
» Problem Solution Discussion Setting Up a MySQL User Account
» Problem Solution Discussion Starting and Terminating mysql
» Problem Solution Discussion Specifying Connection Parameters by Using Option Files
» Problem Solution Discussion Mixing Command-Line and Option File Parameters
» Problem Solution Discussion What to Do if mysql Cannot Be Found
» Problem Solution Discussion Setting Environment Variables
» Problem Solution Discussion Repeating and Editing Queries
» Problem Solution Discussion Preventing Query Output from Scrolling off the Screen
» Problem Solution Discussion Specifying Arbitrary Output Column Delimiters
» Problem Solution Discussion Logging Interactive mysql Sessions
» Discussion Using mysql as a Calculator
» Writing Shell Scripts Under Unix
» Writing Shell Scripts Under Windows
» MySQL Client Application Programming Interfaces
» Perl Connecting to the MySQL Server, Selecting a Database, and Disconnecting
» PHP Connecting to the MySQL Server, Selecting a Database, and Disconnecting
» Python Connecting to the MySQL Server, Selecting a Database, and Disconnecting
» Java Connecting to the MySQL Server, Selecting a Database, and Disconnecting
» Problem Solution Discussion Checking for Errors
» Python Java Checking for Errors
» Problem Solution Discussion Writing Library Files
» Python Writing Library Files
» SQL Statement Categories Issuing Queries and Retrieving Results
» Perl Issuing Queries and Retrieving Results
» Python Issuing Queries and Retrieving Results
» Java Issuing Queries and Retrieving Results
» Problem Solution Discussion Moving Around Within a Result Set
» Problem Solution Discussion Using Prepared Statements and Placeholders in Queries
» Perl Using Prepared Statements and Placeholders in Queries
» PHP Python Java Using Prepared Statements and Placeholders in Queries
» Problem Solution Discussion Including Special Characters and NULL Values in Queries
» Perl Including Special Characters and NULL Values in Queries
» PHP Including Special Characters and NULL Values in Queries
» Python Java Including Special Characters and NULL Values in Queries
» PHP Python Java Handling NULL Values in Result Sets
» Problem Solution Discussion Writing an Object-Oriented MySQL Interface for PHP
» Class Overview Writing an Object-Oriented MySQL Interface for PHP
» Connecting and Disconnecting Writing an Object-Oriented MySQL Interface for PHP
» Error Handling Issuing Queries and Processing the Results
» Quoting and Placeholder Support
» Problem Solution Discussion Ways of Obtaining Connection Parameters
» Getting Parameters from the Command Line
» Getting Parameters from Option Files
» Conclusion and Words of Advice
» Problem Solution Discussion Avoiding Output Column Order Problems When Writing Programs
» Problem Solution Discussion Using Column Aliases to Make Programs Easier to Write
» Problem Solution Discussion Selecting a Result Set into an Existing Table
» Problem Solution Discussion Creating a Destination Table on the Fly from a Result Set
» Problem Solution Discussion Moving Records Between Tables Safely
» Problem Solution Discussion Cloning a Table Exactly
» Problem Solution Discussion Generating Unique Table Names
» Problem Solution Discussion Using TIMESTAMP Values
» Problem Solution Discussion Using ORDER BY to Sort Query Results
» Solution Discussion Working with Per-Group and Overall Summary Values Simultaneously
» Problem Solution Discussion Changing a Column Definition or Name
» Problem Solution Discussion Changing a Table Type
» Problem Solution Discussion Adding Indexes
» Introduction Obtaining and Using Metadata
» Problem Solution Discussion Perl PHP
» Problem Solution Discussion Perl
» PHP Obtaining Result Set Metadata
» Python Obtaining Result Set Metadata
» Java Obtaining Result Set Metadata
» Using Result Set Metadata to Get Table Structure
» Problem Solution Discussion Database-Independent Methods of Obtaining Table Information
» Problem Solution Discussion Displaying Column Lists Interactive Record Editing
» Mapping Column Types onto Web Page Elements Adding Elements to ENUM or SET Column Definitions
» Selecting All Except Certain Columns
» Problem Solution Discussion Listing Tables and Databases
» Problem Solution Writing Applications That Adapt to the MySQL Server Version
» Discussion Writing Applications That Adapt to the MySQL Server Version
» Problem Solution Discussion Determining Which Table Types the Server Supports
» General Import and Export Issues
» Problem Solution Discussion Importing Data with LOAD DATA and mysqlimport
» Problem Solution Discussion Specifying the Datafile Location
» Problem Solution Discussion Specifying the Datafile Format
» Problem Solution Discussion Dealing with Quotes and Special Characters
» Problem Solution Discussion Handling Duplicate Index Values
» Problem Solution Discussion Getting LOAD DATA to Cough Up More Information
» Problem Solution Discussion Dont Assume LOAD DATA Knows More than It Does
» Problem Solution Discussion Skipping Datafile Columns
» Problem Solution Discussion Exporting Query Results from MySQL
» Using the mysql Client to Export Data
» Problem Solution Discussion Exporting Tables as Raw Data
» Problem Solution Discussion Exporting Table Contents or Definitions in SQL Format
» Problem Solution Discussion Copying Tables or Databases to Another Server
» Problem Solution Discussion Writing Your Own Export Programs
» Problem Solution Discussion Converting Datafiles from One Format to Another
» Problem Solution Discussion Extracting and Rearranging Datafile Columns
» Problem Solution Discussion Validating and Transforming Data
» Writing an Input-Processing Loop Putting Common Tests in Libraries
» Problem Solution Discussion Validation by Pattern Matching
» Problem Solution Discussion Using Patterns to Match Numeric Values
» Problem Solution Discussion Using Patterns to Match Dates or Times
» See Also Using Patterns to Match Dates or Times
» Problem Solution Discussion Using Patterns to Match Email Addresses and URLs
» Problem Solution Discussion Validation Using Table Metadata
» Problem Solution Discussion Issue Individual Queries Construct a Hash from the Entire Lookup Table
» Use a Hash as a Cache of Already-Seen Lookup Values
» Problem Solution Discussion Converting Two-Digit Year Values to Four-Digit Form
» Problem Solution Discussion Performing Validity Checking on Date or Time Subparts
» Problem Solution Discussion Writing Date-Processing Utilities
» Problem Solution Discussion Performing Date Conversion Using SQL
» Problem Solution Discussion Guessing Table Structure from a Datafile
» Problem Solution Discussion A LOAD DATA Diagnostic Utility
» Problem Solution Discussion Exchanging Data Between MySQL and Microsoft Access
» Problem Solution Discussion Exchanging Data Between MySQL and Microsoft Excel
» Problem Solution Discussion Exchanging Data Between MySQL and FileMaker Pro
» Problem Solution Discussion Importing XML into MySQL
» Epilog Importing and Exporting Data
» Introduction Generating and Using Sequences
» Problem Solution Discussion Using AUTO_INCREMENT To Set Up a Sequence Column
» Problem Solution Discussion Choosing the Type for a Sequence Column
» Problem Solution Discussion Ensuring That Rows Are Renumbered in a Particular Order
» Problem Solution Discussion Managing Multiple Simultaneous AUTO_INCREMENT Values
» Problem Solution Discussion Using AUTO_INCREMENT Values to Relate Tables
» Problem Solution Discussion Generating Repeating Sequences
» Problem Solution Discussion See Also
» Performing a Related-Table Update Using Table Replacement
» Performing a Related-Table Update by Writing a Program
» Performing a Multiple-Table Delete by Writing a Program
» Problem Solution Discussion Dealing with Duplicates at Record-Creation Time
» Problem Solution Discussion Using Transactions in Perl Programs
» Problem Solution Discussion Using Transactions in Java Programs
» Problem Solution Discussion Using Alternatives to Transactions
» Grouping Statements Using Locks
» Rewriting Queries to Avoid Transactions
» Introduction Introduction to MySQL on the Web
» Problem Solution Discussion Basic Web Page Generation
» Problem Solution Discussion Using Apache to Run Web Scripts
» Problem Solution Discussion Using Tomcat to Run Web Scripts
» Installing the mcb Application
» Installing the JSTL Distribution
» Problem Solution Discussion Encoding Special Characters in Web Output
» General Encoding Principles Encoding Special Characters in Web Output
» Encoding Special Characters Using Web APIs
» Introduction Incorporating Query Results into Web Pages
» Problem Solution Discussion Creating a Navigation Index from Database Content
» Creating a Multiple-Page Navigation Index
» Problem Solution Discussion Storing Images or Other Binary Data
» Storing Images with LOAD_FILE Storing Images Using a Script
» Problem Solution Discussion Retrieving Images or Other Binary Data
» Problem Solution Discussion Serving Banner Ads
» Problem Solution Discussion Serving Query Results for Download
» Introduction Processing Web Input with MySQL
» Problem Solution Discussion Creating Forms in Scripts
» Problem Solution Discussion Creating Multiple-Pick Form Elements from Database Content
» Problem Solution Discussion Loading a Database Record into a Form
» Problem Solution Discussion Collecting Web Input
» Web Input Extraction Conventions Perl
» Problem Solution Discussion Validating Web Input
» Problem Solution Discussion Using Web Input to Construct Queries
» Problem Solution Discussion Processing File Uploads
» Perl Processing File Uploads
» Problem Solution Discussion Performing Searches and Presenting the Results
» Problem Solution Discussion Generating Previous-Page and Next-Page Links
» Paged Displays with Previous-Page and Next-Page Links
» Paged Displays with Links to Each Page
» Problem Solution Discussion Web Page Access Counting
» Problem Solution Discussion Web Page Access Logging
» Problem Solution Discussion Setting Up Database Logging
» Other Logging Issues Using MySQL for Apache Logging
» Session Management Issues Introduction
» Problem Solution Discussion Installing Apache::Session
» The Apache::Session Interface
» A Sample Application Using MySQL-Based Sessions in Perl Applications
» Problem Solution Discussion The PHP 4 Session Management Interface
» Specifying a User-Defined Storage Module
» Problem Solution Discussion Using MySQL for Session BackingStore with Tomcat
» The Servlet and JSP Session Interface A Sample JSP Session Application
Show more