
WhereInQuery( "id", SQLBuilder_MTC.SQLSelect( "" ).From( "some_data" ) ) _ SQLBuilder_MTC.SQLWith( "some_data", SQLBuilder_MTC _ You can use any of these to create a RecordSet. Let's take a simple SQL statement like SELECT * FROM table WHERE i = 1. Each function in the SQLBuilder_MTC.Statement will return itself so you can chain the calls together. To construct SQL, you can either instantiate a new SQLBuilder_MTC.Statement or call SQLBuilder_MTC.SQLSelect( "*" ). Open the included project and copy the SQLBuilder_MTC module into your project. There is only limited error checking so it you want to do something that makes no sense at all, this module won't try to stop you. In other words, it was not designed to meet every need, just the majority of needs. Conversely, it will replace "IS" with "=" and "IS NOT" with "" where the given value is not nil.Įven though I've endeavored for maximum flexibility, there are some situations where using this module will be insufficient or unwieldy.
#Xojo examples code#
When supplying a nil value in a Where clause, the code will substitute "IS NULL" for "=" and "IS NOT NULL" for "" or "!=". If you choose to convert your statement to text, it will be formatted for you in an easy-to-read format. You can generate prepared statement for any type of database without worrying about that database engine's parameter requirements ("$1" vs. You can use the builder to closely match SQL syntax with auto-complete helping at each stage. Where your SQL will depend on outside factors that determine whether certain clauses are included, you can use "conditional where" clauses and avoid messy if constructs. By supplying values in the individual clauses, you can avoid tracking and matching the parameters of a prepared statement to its value. With this, you can use pure Xojo code to craft your queries, making it easier to read, debug, and maintain. Mixing languages can be problematic in any environment. By using this builder, you can keep your SQL close to your code rather than in, for example, a constant, and that makes it easier to debug. There are several advantages to this approach. SQLBuilder_MTC seeks to alleviate some of this burden by allowing you to create smart SQL in code similar to how you might type it out in a text editor. In the latter case, the code to construct the text can get involved and require tracking of values and parameters. Talking to a database involves creating text-based "scripts" in SQL, and these can range from very simple to quite complex. However, you can add code to the TextChange event handler that allows only numbers within a specific range.Xojo classes to build a SQL statement The Goal The new subclass (let’s call it “NumberRangeTextField”) would utilize all of the properties, events, and methods of its super class. A more efficient way is to create a new subclass and choose the NumbersOnlyTextField as its super class. If you found a bug in the code of the NumbersOnlyTextField, you would have to remember that you used that code in other places as well, track them down, and fix them. However, this would make your project larger and more difficult to maintain. You could duplicate the NumbersOnlyTextField subclass and then modify its code. For example, suppose you had a NumbersOnlyTextField subclass, but now you need a TextField that allows only numbers within a certain range. Because subclasses are classes, they can be the super class to other subclasses.
They are called subclasses to differentiate them from the original classes and emphasize the point that they inherit the properties, events, and methods of their parent class. Just right-click (Control-click on Mac) on the custom control class in the Navigator and choose Export. Note: Once created, custom control classes can be exported as self-contained objects that can be used in other projects. When you run the application, the Opening event handler will run and populate the PopupMenu with the months of the year, selecting the current month. To add an instance of the MonthPopup class to a window, switch to the window’s Window Editor and then drag MonthPopup from the Navigator to the Window Editor.