One of CiviCRM’s strengths is the ability to add custom fields to hold specific information about your contacts. One thing it doesn’t offer (yet) is a calculated field type that will present the results of calculations of other fields. While calculated fields are generally discouraged in relational database design, they are sometimes necessary within a user interface. One suggested method is to add custom code hooks within CiviCRM’s PHP code but as a database guy, I decided on a back-end solution.
(Updated June 9, 2016)
One of my current projects involves migrating a large amount of data away from an old custom Borland Paradox application into a new CiviCRM system. As with too many quickly-constructed apps, this old Paradox database wasn’t especially well designed and, among other the other challenges in salvaging the data, there were no restrictions on how dates could be entered. This means that, in multiple fields within each of the 20,000+ database records, I might see any of the following:
03-14-96 5/20/1975 10/02/83 09051975 07.19.1995 19830211121500
While CiviCRM does have a utility for importing data from CSV and other SQL tables, it was having quite a time with this collection and many of the dates were being mishandled. That’s if the records weren’t rejected entirely for other reasons. Data migration doesn’t often happen with just a few settings adjustments and a click of the Import button.
A few months ago, I wrote about how to install MySQL on Windows with IIS. Now I want to show you how to create an AMP web programming stack (Apache, MySQL & PHP) on Mac OS X. As with Windows, you could just go with a ready-made development environment like MAMP but, if you’re going to be doing real database and web design work with MySQL, it’s best to know how everything works.
For this demonstration, I’m going to be using Mac OS X El Capitan (v.10.11), the latest version as of this writing. My installation environment is a hosted Mac server with 1 GB of RAM and 40 GB of disk space. I will be demonstrating the process using the Terminal commands.
Unlike Windows, OS X already includes the Apache web server and PHP language pre-installed so it’s a much simpler process to ensure that everything is working together. You will need root access in order to install and configure the components.
Occasionally, when you’re making a lot of design changes to a Microsoft Access database, Access might start crashing when you’re working with that specific database file or when trying to enter the VBA environment with ALT-F11. This leaves you unable to investigate the issue or make further changes. It can be a sign that there are errors within the project’s compiled VBA code. One solution is to use the /decompile switch to remove the compiled VBA code from the project and then recompile the source code.
If you’re doing ongoing design work with Access, I recommend creating a new shortcut to the MSACCESS.EXE file on your system with the decompile switch. You would use this only when trying to recover a file. The rest of the time, you should use the normal menu shortcut.
"C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.EXE" /decompile
You can also enter this with the Run command on the Start menu and include the path to your database file after the /decompile switch.
The first file that you open after running Microsoft Access with this switch will be decompiled. This will not delete the source code behind your forms or reports but it will remove the compiled version of the code and might enable you to get back into the VBA environment.
Once you’re in VBA, use the Debug >> Compile Database command to recompile the database project. This will enable you to find and correct any problems within the code.
As always, be sure to make regular backups of your files as you’re coding in case this doesn’t work and you have to recover. Also be sure to make a backup of the file before you try to decompile it in case something goes wrong.
If this doesn’t work, then the last resort is to rebuild your database by importing all of the objects within it into a new database file. This is time consuming, however, although it does seem to remove a lot of temporary data that Access stores in the file, reducing the database size substantially in some cases.
My newest book, MySQL Explained, is due to be published this month! You can check out the LeanPub page to show your support and to sign up for notifications of when it’s published. See the description of the book below.
UPDATE 10/24/2015 – MySQL Explained is now available in both EPUB and MOBI (Kindle) formats with the first chapter available for FREE from LeanPub.com and Amazon.com! Read more about this guide to the leading database for online applications and on the official page!
About the Book
MySQL Explained is a step-by-step tutorial for everyone who’s ready to learn about the database software most commonly used for storing information behind some of today’s most popular websites and online applications.
Written especially for people outside the I.T. world, MySQL Explained provides the background information you need to get familiar with database theory and the principles behind organizing data. This book starts from the ground up, helping the reader to understand the very definition of a database, the forms it can take and the different options for storing information. By the end of this book, you’ll understand the reasons for choosing MySQL, the options for installing it and the tools that it offers to store and safeguard your data.
If you are in any way involved in designing or managing a website or data solution of any kind, you owe it to yourself to understand the tools involved. Quality database management sytems are essential in today’s data-driven world and such essential tools should not be a mystery to those who depend on them. MySQL Explained can help you unravel the mystery and learn more about a technology that will be around for a long time to come.
MySQL Explained is published through OS Training which, in addition to publishing tutorials like this one, offers onsite and online training in web technologies including Joomla, Drupal and WordPress.
Just as a reminder, my first book, Microsoft Access for Beginners, is still available as a free download in PDF format from Scribd.com. This book covers versions of Access through 2010 and I’m not planning on updating it further at this time but much of the information is still applicable to the current version of Access. If you’ve been wanting to get an introduction to Microsoft’s desktop database software, this is a great place to start. You’ll learn the principles of organizing data into tables, writing queries on those tables and creating the forms and reports to work with your data as needed. If you’re interested general database principles in addition to Access, please see my other book, Your First Guide to Database Design which is available from both Amazon.com (Kindle edition) and Scribd.com (PDF).
The word database is not one that you hear in everyday conversation. It’s one of those technical terms that’s used by business and I.T. people. It might evoke images of computers and long reports of names and numbers or indecipherable data. Some people might think of marketing or mailing lists. In fact, a database is simply any collection of data that’s organized so that it can be retrieved and used as needed. Usually, it refers specifically to data that has been stored within a computer system so that it can be quickly manipulated into reports. Databases take many forms but anytime a computer needs to present information of any kind, whether it be a store’s customer data or patient data at your doctor’s office, that data has to be retrieved from somewhere and it’s usually in a database of one kind or another.
In a previous chapter, I described the installation process for SQL Server 2012 Express which included all the bells and whistles of the advanced services package. While it’s great to have all the tools at your disposal to learn from, some people might not want such a large installation on a particular machine or the administration that goes with it but might still want the basic database capabilities of SQL Server on their desktop. In this case, SQL Server 2012 offers a new edition called LocalDB.
LocalDB is a minimized version of SQL Server Express specifically for developers who still need all the programming features including the ability to create stored procedures and other objects within an instance of SQL Server. It has a few restrictions that the average beginner probably won’t be bothered by and you can connect to it with SQL Server Management Studio (SSMS) or other tools to create and manage databases. You can even install the AdventureWorks sample database to work with through an instance of LocalDB.
In this article, I’ll describe the process of installing both LocalDB and SSMS in order to create a small desktop database environment to work with as a developer or a beginner in database design.
In the last part of this series I wrote about SQL Server Management Studio (SSMS), the interface that enables you to work with SQL Server objects such as databases and tables. The program enables you to do quite a bit with a SQL Server installation. You can create entire databases and manipulate all the objects within them just through context menus.
Having a graphical interface is nice but the real work of SQL Server is done through commands issued to the service which the menu options in a program like SSMS often do for you. If you really want to be knowledgeable about SQL Server, it’s important to learn the syntax of these commands and how to write and issue them on your own.
Once you have SQL Server and all the necessary updates installed, the next step is to learn how to create databases and work with them. The easiest interface available to the beginner is Microsoft SQL Server Management Studio (SSMS), a graphical environment where you can view and manipulate all of the databases and other objects on your SQL Server instance and perform other advanced functions.
If you installed the Express edition with Management Tools or Advanced Tools as detailed in the last chapter, you should have SSMS installed and showing in the Program Menu under whichever version of SQL Server you have installed. Just click on the program to open it.