Professional Documents
Culture Documents
Applications with
Visual FoxPro
Whil Hentzen
Hentzenwerke Publishing
Published by:
Hentzenwerke Publishing
980 East Circle Drive
Whitefish Bay WI 53217 USA
Hentzenwerke Publishing books are available through booksellers and directly from the
publisher. Contact Hentzenwerke Publishing at:
414.332.9876
414.332.9463 (fax)
www.hentzenwerke.com
booksales@hentzenwerke.com
MySQL Client-Server Applications with Visual FoxPro
By: Whil Hentzen
Technical Editor: Ted Roche
Copy Editor: Nicole Robbins-McNeish
Cover Art: Teaching Tricks by Todd Gnacinski, Milwaukee, WI
Copyright 2007 by Whil Hentzen
All other products and services identified throughout this book are trademarks or registered
trademarks of their respective companies. They are used throughout this book in editorial
fashion only and for the benefit of such companies. No such uses, or the use of any trade name,
is intended to convey endorsement or other affiliation with this book.
All rights reserved. No part of this book, or the ebook files available by download from
Hentzenwerke Publishing, may be reproduced or transmitted in any form or by any means,
electronic, mechanical photocopying, recording, or otherwise, without the prior written
permission of the publisher, except that program listings and sample code files may be entered,
stored and executed in a computer system.
The information and material contained in this book are provided as is, without warranty of
any kind, express or implied, including without limitation any warranty concerning the
accuracy, adequacy, or completeness of such information or material or the results to be
obtained from using such information or material. Neither Hentzenwerke Publishing nor the
authors or editors shall be responsible for any claims attributable to errors, omissions, or other
inaccuracies in the information or material contained in this book. In no event shall
Hentzenwerke Publishing or the authors or editors be liable for direct, indirect, special,
incidental, or consequential damages arising out of the use of such information or material.
ISBN: 1-930919-70-0
Manufactured in the United States of America.
List of Chapters
Chapter 1: Why Client-Server? Why VFP? Why MySQL?
Chapter 2: Development and Deployment Scenarios
Chapter 3: Installing MySQL on Windows
Chapter 4: Installing MySQL on Linux
Chapter 5: Configuration of Users and Hosts
Chapter 6: Connecting VFP to MySQL
Chapter 7: Configuring MySQL
Chapter 8: The Interactive Use of MySQL
Chapter 9: Under the Hood: Where MySQL Keeps Its Data
Chapter 10: Creating Data Sets from Scratch
Chapter 11: Populating a MySQL Database: LOAD DATA INFILE
Chapter 12: Populating a MySQL Database Programmatically
Chapter 13: Advanced Data Issues
Chapter 14: Constructing SQL to Avoid SQL Injection
Chapter 15: Religious Wars: Remote Views, CursorAdapters,
and SQL PassThrough
Chapter 16: A Client-Server State of Mind
Chapter 17: xBase to SQL Conversion Issues
Chapter 18: A Client-Server User Interface for Querying
Chapter 19: A Client-Server User Interface for Add/Edit/Delete
Chapter 20: Relational Integrity
Chapter 21: Getting Started with Stored Procedures
Chapter 22: Deployment
1
17
25
55
75
93
119
151
173
181
211
219
249
263
271
287
295
317
335
369
379
393
vii
Table of Contents
Our Contract with You, The Reader
Acknowledgments
About the Author
How to Download the Files
Introduction
Chapter 1: Why Client-Server? Why VFP? Why MySQL
What is Client-Server?
Why Client-Server?
Data access and security
Backup
Replication
Clustering
Stored procedures
Referential integrity
Scalability
What is VFP?
Why VFP?
Technical reasons
Business reasons
What is MySQL?
Why MySQL?
Technical reasons
Business reasons
Arguments against
FoxPro is dead (or obsolete, or not supported, or...)
Visual FoxPro wont have a native 64 bit version
ODBC is too old/slow
MySQLs SQL is not compliant or standard
Conclusion/Summary
iii
xvii
xix
xxi
xxiii
1
2
3
3
3
3
3
3
4
4
4
5
5
8
9
9
10
11
12
12
13
13
14
15
17
17
17
18
19
19
20
20
23
24
viii
25
25
25
26
26
26
26
27
30
30
30
31
31
31
38
47
47
49
50
52
52
53
54
55
55
55
56
56
57
58
58
62
62
64
64
65
66
66
66
67
69
69
70
71
ix
72
73
74
75
75
75
76
83
83
83
84
85
86
86
87
89
90
91
93
93
93
93
94
99
99
108
114
114
115
116
116
118
119
119
119
121
122
124
124
128
131
133
The Administrator
Editing the my.ini/my.cnf file directly
Specific settings in the MySQL configuration file
Conclusion/Summary
140
147
148
149
151
151
151
152
152
156
156
156
159
161
167
170
171
173
173
173
174
175
176
176
177
177
179
180
181
181
181
182
183
184
184
185
186
189
190
190
191
192
xi
Field attributes
Indexes
Creating primary keys
Assigning foreign keys
Working with time stamps
End result: empty data set what's it look like?
mysqlshow
SQL commands
Getting data into the database
Conclusion/Summary
195
198
199
200
205
206
206
207
210
210
212
212
213
214
214
214
215
218
219
219
220
220
220
222
223
224
224
224
225
226
227
227
229
229
230
231
231
231
232
234
234
235
236
xii
236
236
237
239
240
241
242
243
243
244
246
246
247
248
249
249
249
250
252
253
253
254
256
257
257
258
258
258
259
259
259
260
261
261
263
263
264
265
266
266
266
266
267
269
xiii
Conclusion/Summary
270
271
271
271
282
282
283
283
284
284
285
285
285
285
285
286
287
288
288
288
288
290
290
290
291
291
291
291
292
293
295
295
295
295
295
297
297
297
299
299
300
xiv
Math functions
Lists, comparison, logic functions
Empty/Blank/NULL functions
Data/database functions
String functions
Date functions
System information functions
Miscellaneous functions
Conclusion/Summary
301
303
305
305
307
310
314
315
315
317
317
319
319
320
321
322
325
326
326
326
327
327
329
330
331
332
333
333
334
335
336
336
337
338
339
340
341
341
343
345
346
347
350
xv
350
352
354
354
355
357
360
362
362
363
363
365
365
366
367
369
369
371
374
374
375
375
376
376
376
377
377
379
379
379
379
381
382
383
383
384
384
385
385
387
387
388
389
389
xvi
390
391
393
393
394
394
394
395
395
395
397
400
400
400
400
401
401
402
402
403
403
Chapter 7
Configuring MySQL
MySQLs operation is controlled by a configuration file. You can use a graphical frontend, called the MySQL Administrator, to change this file, or you can edit this file directly.
In this chapter, Ill first show you how to install and use the Administrator. Once youre
comfortable with this tool, Ill cover the essential configuration items youll want to look
at and possibly tweak yourself, and then briefly cover the rest of the settings. Finally, Ill
discuss how to edit the configuration file directly.
The MySQL configuration file is a plain text file that is referenced during the startup of the
MySQL server as well as MySQL client applications. The documentation inside the file is
outstanding, and I urge you to read through it even if youre not planning on ever editing it
directly yourself.
But first, you need to know where to find it.
my.ini in Windows
On Windows, MySQL server looks for a file named my.ini. While the my.ini file is typically
in the same directory as the mysql executable, an argument is passed to the MySQL service
command that explicitly identifies where this file is.
On Windows, the syntax looks like this:
"C:\mysql\bin\mysqld-nt" --defaults-file="C:\mysql\my.ini" MySQL
You can find out what my.ini file is being used in your Windows installation via the
Services applet. Click on the Services applet in the Administrative Tools window in Control
Panel to open the Services list, as shown in Figure 1.
120
Figure 2. The location of the my.ini configuration file is in the executable path.
Youll see the configuration file being used by the current MySQL service displayed in
the read-only text box under Path to executable: the text box is read-only because it is
normally modified via manual MySQL commands or through the GUI tool.
my.cnf in Linux
On Linux, MySQL looks for a configuration file named my.cnf located in the /etc directory:
/etc/my.cnf
This file controls global options. Because you can have multiple MySQL databases
running on a single physical machine, you might think it would be convenient to be able to
specify specific configuration settings, and you can. You can specify server-specific options
by placing a copy of this file in the data directory for the server, like so:
/var/lib/mysql/my.cnf
122
and modifying the file accordingly. Even further fine-tuning is available on a user-by-user
case by placing a copy of this file in the users home directory, like so:
/home/<username>/my.cnf
Clicking the link takes you to a list of files for various operating systems, as shown in
Figure 4.
(or later) to your hard disk; clicking the download link in the SUSE Linux 9.3 section will
download a file named
mysql-administrator-1.1.6-1.suse93.i586.rpm
in a similar manner.
124
Clicking the Next button takes you to the Destination Folder dialog. At this point, the
default is usually under C:\Program Files if you changed the default installation directory of
MySQL to something like C:\mysql, then I suggest you change the installation directory of the
administrator also so it is still under the main MySQL directory, like so:
c:\mysql\admin1.1
126