to make things
easier
WestWind
Web Connection is a great tool for all sorts of development efforts. I'm not a big fan of
views, or cursoradapters in VFP development. I prefer the rough and tumble SQL Pass Through (SPT)
method of manipulating data. The wwSQL class helps take the pain out of SPT for me. There are two
methods in particular that really help: SQLBuildInsertStatementFromObject and
SQLBuildUpdateStatementFrom Object. These methods accept an object as the first parameter, and the
name of the target table as the second parameter, and creates a string containing a valid INSERT or
UPDATE command matching the contents of the object.
There is a problem however. WestWind
targets these methods at either VFP tables or SQL Server
tables. There are some differences between SQL Server INSERT statements and MySQL INSERT
statements. I probably haven't found all of the differences, but the changes are minor.
The big difference is the representation of the empty date. In SQL Server, the empty date can be
represented by the empty string. In MySQL, the empty date is represented by a series of zeros in the
format of '00000000'.
WestWind
also wraps field names in square brackets to help avoid problems
with spaces in field names, and also to avoid problems with reserve words. In MySQL, fields wrapped
in square brackets throws an error.
So, I have subclassed the wwSQL class and created three new properties: cEmptyDate,
cFieldParamLeft, and cFieldParamRight. When in use against a MySQL table, I have populated
cEmptyDate with the zero formatted string as above, and set the cFieldParamLeft and
cFieldParamRight with the empty string as well.
I then overrode the SQLBuildInsertStatementFromObject and the
SQLBuildUpdateStatementFromObject to draw from these properties and it works like a charm. As a
side note, I have also created a function named DtoMySQLDate( toDate AS Date) function that returns
a date formatted as '20070620'
no matter what SET DATE is set to.
I hope that you have gotten some tips in how to get VFP to access a MySQL server. Once you try it, I
think you will find it a fast, robust, and inexpensive alternative to other solutions.
Kevin
Friday, January 23, 2009
ENGINE talk
MySQL allows for different databases to be governed by different engines. Two of the most popular is
MyISAM and INNODB. To bottom line the difference is that MyISAM does not support transactions,
while INNODB does. The performance difference between the two engines is just a couple of
percentage points, one way or the other based on my simple benchmarks that I have performed. There
are other benchmark statistics performed by far smarter and qualified people than myself, so run some
tests before you get started.
Remember that XAMPP has the INNODB engine turned off by default. A quick edit to my.cnf will add
it back in after a restart.
MyISAM and INNODB. To bottom line the difference is that MyISAM does not support transactions,
while INNODB does. The performance difference between the two engines is just a couple of
percentage points, one way or the other based on my simple benchmarks that I have performed. There
are other benchmark statistics performed by far smarter and qualified people than myself, so run some
tests before you get started.
Remember that XAMPP has the INNODB engine turned off by default. A quick edit to my.cnf will add
it back in after a restart.
How to upsize VFP structures and data to MySQL
1. Upsizing wizard in VFP requires a DBC
2. Stru2MySQL.prg by Ed Leafe.
3. Stru2MySQL_2.prg – additions by Kevin Cully
The changes that I have made to Stru2MySQL include:
1. Script files are created for each open cursor/table
2. A script file is created that contains all of the individual script files.
3. The program creates an object, that can have properties/options set to better control the output.
4. Additional MySQL commands are added to the script which drops existing tables if they exist.
5. The program allows for alternative engines to be specified. INNODB vs. MyISAM as an
example.
I'll have the Stru2MySQL_2.prg uploaded back to Ed Leafe's downloads page at
http://leafe.com/dls/vfp. Feel free to make improvements and donate back to the community.
2. Stru2MySQL.prg by Ed Leafe.
3. Stru2MySQL_2.prg – additions by Kevin Cully
The changes that I have made to Stru2MySQL include:
1. Script files are created for each open cursor/table
2. A script file is created that contains all of the individual script files.
3. The program creates an object, that can have properties/options set to better control the output.
4. Additional MySQL commands are added to the script which drops existing tables if they exist.
5. The program allows for alternative engines to be specified. INNODB vs. MyISAM as an
example.
I'll have the Stru2MySQL_2.prg uploaded back to Ed Leafe's downloads page at
http://leafe.com/dls/vfp. Feel free to make improvements and donate back to the community.
How To Install MySQL
I won't go into too much detail here about how to install MySQL. Partly because it is so easy. Go to
http://mysql.org/downloads/ and download the server for your platform. Make sure to check out the
“GUI Tools” section. It will really help administer your MySQL installation. I'll talk about the GUI
tools a bit later.
Another approach to take is to take a look at XAMPP at http://www.apachefriends.org/en/xampp.html.
XAMPP is a suite of FOSS goodness that includes Apache, MySQL, PHP, PHPmyAdmin and other
great packages. All in one easy to install bundle. Recommended.
One note is that XAMPP has the INNODB engine turned off by default. You'll need to adjust the
my.cnf file to have it turned on. More on this later.
What GUI tools are available to Administer and query
MySQL
There is not a shortage of GUI tools to help you administer and query the data that you have stored in
MySQL. Here are just a couple of the tools. Some are current, others are being moonlighted, and
others are still in beta.
1. MySQL Administrator – An administrative tool that enables you to control your environment
and gain better visibility into how your databases are operating.
2. MySQL Control Center – Another administrative tool that allows you to create and modify most
of the database objects in a trivial manner.
3. MySQL Query Browser – One of the easiest tools for creating, executing, and optimizing SQL
queries for your database.
4. PHPMyAdmin – A web based administrative tool that allows you to create databases, tables,
indexes, administer rights, etc. All in a browser.
http://mysql.org/downloads/ and download the server for your platform. Make sure to check out the
“GUI Tools” section. It will really help administer your MySQL installation. I'll talk about the GUI
tools a bit later.
Another approach to take is to take a look at XAMPP at http://www.apachefriends.org/en/xampp.html.
XAMPP is a suite of FOSS goodness that includes Apache, MySQL, PHP, PHPmyAdmin and other
great packages. All in one easy to install bundle. Recommended.
One note is that XAMPP has the INNODB engine turned off by default. You'll need to adjust the
my.cnf file to have it turned on. More on this later.
What GUI tools are available to Administer and query
MySQL
There is not a shortage of GUI tools to help you administer and query the data that you have stored in
MySQL. Here are just a couple of the tools. Some are current, others are being moonlighted, and
others are still in beta.
1. MySQL Administrator – An administrative tool that enables you to control your environment
and gain better visibility into how your databases are operating.
2. MySQL Control Center – Another administrative tool that allows you to create and modify most
of the database objects in a trivial manner.
3. MySQL Query Browser – One of the easiest tools for creating, executing, and optimizing SQL
queries for your database.
4. PHPMyAdmin – A web based administrative tool that allows you to create databases, tables,
indexes, administer rights, etc. All in a browser.
Thursday, January 1, 2009
Tutorial Borland C++ Builder
Borland C++ Builder 1
C++ Builder can be used to create 32-bit Windows applications ranging from general-purpose utilities to sophisticated data access programs. When you start C++ Builder, you are placed within the object-orientated integrated development environment, the IDE. This environment provides all the tools you need to design, develop, test, debug, and deploy applications. To launch the IDE for C++ Builder, choose Programming from the Public menu on the Windows taskbar then choose C++ Builder5 from the ++ Builder option: The initial screen should appear like this:
Across the top of the window is the title bar with the minimise, maximise and close buttons on the right-hand side. Under the title bar are ten menus. The File, Edit and Search menus have all the usual Windows options, whilst the other menus contain options specific to the C++ Builder environment. The View menu allows you to view a number of windows containing program and environment information. Borland C++ Builder Introduction Starting The IDE The Menus 2 Borland C++ Builder The Project menu is for the manipulation of project files and control of all aspects of a project, allowing you to compile all or part of a program. The Run menu provides facilities testing and debugging the application. The Component menu allows for defining, specificatio and insertion of external objects into the application. The Database menu provides ways of interacting with several types of live database. The Tools menu allows you to run other programs, tools and utilities useful in the development of Windows applications, without leaving the IDE. The Help menu gives you access to on-line help including tutorials, programming syntax, examples and library information. Below the menu bar to the left is a block of buttons that represent commonly performed tasks: Pointing to a button will display its function.
To the right of the button bars is the Component Palette: Each tab in the Component Palette displays a group of icons representing the components you can use to design your application interface such as menus, buttons and dialogue boxes. These are the building blocks of every application. The main part of the IDE screen is taken up by a blank form on which you will create the user interface and other parts of your applicaion by placing components on it. The default form has Maximise and Minimise buttons, a Close button, and a Control menu. If you run the form now by pressing F9, you'll see that these buttons all work. (To return to design mode, click the X to close the form.) To the left of the Form is the Object Inspector. This is the connection between your application's visual appearance and the code that makes your application run. The object selector at the top of the Object Inspector is a dropdown list containing all the components that you have placed on the active form and it also displays the object type of the selected component. This lets you quickly display properties and events for the different components on the current form. The Object Inspector has two sections, the Properties page and the Events page with tabs provided as a means of switching between them. The Button Bars The Component Palette The Form The Object Inspector Borland C++ Builder 3 Before beginning a new application, you should create a folder to hold the source files. Each application is represented by a project. When you start C++ Builder, it creates a blank project by default. If another project is already open, choose New Application from the File menu to create a new project. A new project, automatically contains the following files: Project1.cpp - a source-code file associated with the project. Unit1.cpp - a source-code file associated with the main project form. This is called a unit file. Unit1.h - a header file associated with the main project form. This is called a unit header file. Unit1.dfm - a resource file that stores information about the main project form. This is called a form file. Each form has its own unit, header, and form files. If you
create a second form, a second unit (Unit2.cpp), header (Unit2.h), and form (Unit2.dfm) file are automatically created. You should save these files to the folder you have just created by choosing Save All from the File menu. When the Save dialogue appears: Navigate to your project folder.
Save Unit1 using the default name Unit1.pas.
Save the project using appname.bpr.
Where appname is a name of your choice.
You are now ready to add components to the form and to
associate actions and properties to them. Use the Help menu,
which contains tutorial assistance, to take you through
creating a simple application.
You should periodically resave your work by choosing Save All
from the File menu. When you save your project, C++ Builder
creates additional files in your project directory. These files
include:
appname.bpr which is the project options or makefile,
appname.res which is the Windows resource file.
You do not need to worry about these files but do not delete
them. The executable file for your application will be named
the same as the project name with an exe extension.
To compile and test your application at any time, choose Run
from the Run menu.
Once an application is up and running, you need to make it
available for others. A number of steps must be taken to deploy
an application to another computer so that the application is
completely functional.
The steps required vary, depending on the type of application.
It may require a number of supporting files such as DLLs or
helper applications. It may also require changes to be made to
the receiving computer's Windows registry. Consult the C++
Creating And
Running a Program
Adding Components
Saving The Project
Compiling And Testing
Deploying Applications
4 Borland C++ Builder
Builder Help section under the Help menu for details of how to
prepare your application for installation to other computers.
To end your session in the C++ Builder IDE, choose Exit from
the File menu.
Ending C++ Builder
C++ Builder can be used to create 32-bit Windows applications ranging from general-purpose utilities to sophisticated data access programs. When you start C++ Builder, you are placed within the object-orientated integrated development environment, the IDE. This environment provides all the tools you need to design, develop, test, debug, and deploy applications. To launch the IDE for C++ Builder, choose Programming from the Public menu on the Windows taskbar then choose C++ Builder5 from the ++ Builder option: The initial screen should appear like this:
Across the top of the window is the title bar with the minimise, maximise and close buttons on the right-hand side. Under the title bar are ten menus. The File, Edit and Search menus have all the usual Windows options, whilst the other menus contain options specific to the C++ Builder environment. The View menu allows you to view a number of windows containing program and environment information. Borland C++ Builder Introduction Starting The IDE The Menus 2 Borland C++ Builder The Project menu is for the manipulation of project files and control of all aspects of a project, allowing you to compile all or part of a program. The Run menu provides facilities testing and debugging the application. The Component menu allows for defining, specificatio and insertion of external objects into the application. The Database menu provides ways of interacting with several types of live database. The Tools menu allows you to run other programs, tools and utilities useful in the development of Windows applications, without leaving the IDE. The Help menu gives you access to on-line help including tutorials, programming syntax, examples and library information. Below the menu bar to the left is a block of buttons that represent commonly performed tasks: Pointing to a button will display its function.
To the right of the button bars is the Component Palette: Each tab in the Component Palette displays a group of icons representing the components you can use to design your application interface such as menus, buttons and dialogue boxes. These are the building blocks of every application. The main part of the IDE screen is taken up by a blank form on which you will create the user interface and other parts of your applicaion by placing components on it. The default form has Maximise and Minimise buttons, a Close button, and a Control menu. If you run the form now by pressing F9, you'll see that these buttons all work. (To return to design mode, click the X to close the form.) To the left of the Form is the Object Inspector. This is the connection between your application's visual appearance and the code that makes your application run. The object selector at the top of the Object Inspector is a dropdown list containing all the components that you have placed on the active form and it also displays the object type of the selected component. This lets you quickly display properties and events for the different components on the current form. The Object Inspector has two sections, the Properties page and the Events page with tabs provided as a means of switching between them. The Button Bars The Component Palette The Form The Object Inspector Borland C++ Builder 3 Before beginning a new application, you should create a folder to hold the source files. Each application is represented by a project. When you start C++ Builder, it creates a blank project by default. If another project is already open, choose New Application from the File menu to create a new project. A new project, automatically contains the following files: Project1.cpp - a source-code file associated with the project. Unit1.cpp - a source-code file associated with the main project form. This is called a unit file. Unit1.h - a header file associated with the main project form. This is called a unit header file. Unit1.dfm - a resource file that stores information about the main project form. This is called a form file. Each form has its own unit, header, and form files. If you
create a second form, a second unit (Unit2.cpp), header (Unit2.h), and form (Unit2.dfm) file are automatically created. You should save these files to the folder you have just created by choosing Save All from the File menu. When the Save dialogue appears: Navigate to your project folder.
Save Unit1 using the default name Unit1.pas.
Save the project using appname.bpr.
Where appname is a name of your choice.
You are now ready to add components to the form and to
associate actions and properties to them. Use the Help menu,
which contains tutorial assistance, to take you through
creating a simple application.
You should periodically resave your work by choosing Save All
from the File menu. When you save your project, C++ Builder
creates additional files in your project directory. These files
include:
appname.bpr which is the project options or makefile,
appname.res which is the Windows resource file.
You do not need to worry about these files but do not delete
them. The executable file for your application will be named
the same as the project name with an exe extension.
To compile and test your application at any time, choose Run
from the Run menu.
Once an application is up and running, you need to make it
available for others. A number of steps must be taken to deploy
an application to another computer so that the application is
completely functional.
The steps required vary, depending on the type of application.
It may require a number of supporting files such as DLLs or
helper applications. It may also require changes to be made to
the receiving computer's Windows registry. Consult the C++
Creating And
Running a Program
Adding Components
Saving The Project
Compiling And Testing
Deploying Applications
4 Borland C++ Builder
Builder Help section under the Help menu for details of how to
prepare your application for installation to other computers.
To end your session in the C++ Builder IDE, choose Exit from
the File menu.
Ending C++ Builder
Subscribe to:
Posts (Atom)
