Seek and ye shall…
A database without a search function is like a car without an engine. The second part of our Base series is dedicated to implementing a database search.
|
A database without a search function is like a car without an engine. The second part of our Base series is dedicated to implementing a database search.
The first part of this tutorial [1] explained how to create an image database with easy input masks and a tagging system (Figure 1). It satisfied the Base [2] claim that you can do database programming using mouse clicks instead of having to resort to SQL in Linux. Wizards and a graphical query editor do the work and let even users without programming experience create a database, forms, and queries.
The Base application from the first article lacked just one important feature: a search function (Figure 2). However, this task is one where the graphical helpers in Base are not going to help much – you can't do it without getting down and dirty with SQL.
A query that filters matching records by keyword is not something the graphical editor can handle. It requires SQL code – such as programmers use to communicate with the database – fortunately, you're only going to need homeopathic-like dosages.
The task of inserting a user search string in an otherwise fixed query can be implemented in Base only through a back door. Figure 3 shows how it works. The Filter table (in yellow) contains only a record with a search string – in this example, the Title .
A subform changes the Title stored in Filter – similar to the Categories subform shown in the first part of this tutorial. The search query (in red) compares the Filter title with the Title fields in the Images table (in blue) and returns a record where the two match.
Figure 2 shows an extended version of the Images form. At the top, you can see the filter function highlighted in blue that searches for images with a particular Title . Leaving the field empty means scrolling through all the records as usual. Entering a value returns only those records matching the search string.
To build on the familiar, you can first create a table called Filter , which contains a VARCHAR field called Title that takes the modifiable search string. Allow Base to create a primary key for it automatically; otherwise, the content can't be changed by the form.
Next, you'll need another form that accesses the Filter table. Open the form navigator and right-click Forms to choose the Filter form. Because this form controls the data display in the previous main form, drag the MainForm to Filter to subordinate it.
The next step is to bind the Filter form with the table of the same name. Use the Forms button in the left button bar (the fourth from the top) to open the settings palette for the form.
Figure 4 shows the required settings for the Data tab. After selecting the table, you'll find the Cycle setting for Active record . This ensures that you don't add any new records but only change existing ones – because only valid entries can be used as search strings.
Pages: 3
Creating database applications with wizards and graphic editors – without SQL and programming – that's what the LibreOffice program Base, modeled after Microsoft Access, is all about.
From simple queries to complex menus: Using dialog, you can create a graphical interface for shell scripts with only a few extra lines of code.
The easiest way to save space for digital videos is to reach for Avidemux and convert them with just a few mouse clicks.
When you get back from a trip, you're usually bursting to tell everybody all about it and share your photos. Organizing your pics by location makes it easier to describe your adventures.
SQLiteStudio, a compact graphical tool, lets you complete everyday tasks relating to SQLite databases quickly and easily.
© 2024 Linux New Media USA, LLC – Legal Notice