Showing entries 41 to 50 of 111
« 10 Newer Entries | 10 Older Entries »
Displaying posts with tag: coding (reset)
MySQL University: Good Coding Style

This Thursday (March 5th, 14:00 UTC), Konstantin Osipov will give a MySQL University session on Good Coding Style. Konstantin is the lead of the server runtime environment team, and has been around at MySQL since 2003.

For MySQL University sessions, point your browser to this page. You need a browser with a working Flash plugin. You may register for a Dimdim account, but you don't have to. (Dimdim is the conferencing system we're using for MySQL University sessions. It provides integrated voice streaming, chat, whiteboard, session recording, and more.) All MySQL University sessions are recorded, that is, slides and voice can be viewed as a Flash movie (.flv). You can find those …

[Read more]
MySQL Workbench - LUA-Script For Batch Renaming Of Foreign Keys

Yesterday there was a short discussion on our public IRC channel (#workbench on freenode). It was about how Workbench handles Foreign-Key-Names.

Especially if you intend to use Synchronization feature (available in SE edition only) its good to have names for FKs (and their coresponding Indices). Workbench does that by default if you’re using the Relationship-tools (Hotkeys 1 to 6 when canvas is focused). But if you prefer to create your FKs in a not-so-visual way (entering the values on the FK-Tab in the table-Editor) you are on your own when it comes to naming your FKs. Though Workbench initially only accepts creating keys after you typed a name into the name-field theres still the possibility to rename the FK later to even empty names. If you try to create empty named FKs on a MySQL Server the server will generate a name for the key.

If you want to change FK names later, when your model has already grown to a size, where …

[Read more]
MySQL Storage Engine based on PHP

Sometimes one has weird ideas, or am I the only one? - This specific one is at least a year old, now, during the Christmas days, waiting for New Year's Eve I had the time and mood to finally try it out: MySQL 5.1 has a plugin interface to easily add storage engines. PHP can easily embedded into other applications.  So why not combine these two things? - Writing a MySQL Storage Engine which reads data by calling a PHP script.

Let's start with a simple example first:

<?phpfunction create_table($table, $data) {
    return true;
}

function open_table($table) {

[Read more]
Direct MySQL Stream Access

Ever wondered what your PHP application and MySQL actually do? An experimental mysqlnd branch will give you full access to the network communication stream. Using a custom PHP stream filter you can then intercept the communication ... but let's start at the beginning:

When talking about mysqlnd - the mysql native driver for PHP - we always mention the fact it's native in a way that we're, when possible, using PHP infrastructure. The most common example here is the memory management. By directly using PHP's memory we can avoid unnecessary copies of data from the MySQL Client Library's memory into PHP memory.

<?php
$mysqli = mysqli_connect("localhost", "root", "", "test");
$stream = mysqli_conn_to_stream($mysqli);

[Read more]
Automate Figure Arrangement In Workbench

Initiated by a question on the forum I took some time to exercise my Workbench-Scripting-Knowledge. The question was, if it’s possible to do some figure-arrangement/organizing via scripts. To be more precise, the task I had to master was to get tables that have names starting with a given prefix moved into a new layer using scripts.

The function to create a new object - layer in this case - was an easy one. All you have to do is to use the function grtV.newObj(”workbench.model.Layer”). This function returns a handle to the created Layer. Finally, set the visual properties (color, position) and most important, the owner has to be set to the containing Diagram-object. Last step is to add the layer to the “layers” property of the Diagram-object.
The second step, which i put into a separate function, is to ask the user for the prefix to filter the desired tables/objects that should get grouped onto the new layer. Next, loop …

[Read more]
The power of a good SQL naming convention

At my previous employer, one of the early decisions that had huge payoffs later was the SQL naming conventions. A good naming convention is more than just a nicety. It lets you write programs that don’t need to be told about the relationships among tables and columns.

There are many ways to do this, [...]

More on DTrace ... and MySQL

Angelo recently showed an easy way to dump SQL queries using DTrace, while reading the articles I felt that some important information is missing: The name of the user executing the query and the selected database. So I sat down a few minutes and tried to collect that data.

For the database name I found a quite simple solution: It is passed as parameter to the check_user() function to MySQL so we can easily add a thread-local variable to keep that name. Simple script for that:

#!/usr/sbin/dtrace -s

#pragma D option quiet

pid$1::*check_user*:entry
{
self->db = arg4 ? copyinstr(arg4) : "(no schema)";
}

pid$1::*dispatch_command*:entry
{
printf("%s: %s\n", self->db, copyinstr(arg2));
}

Getting the username is a bit harder, for the …

[Read more]
Launchpad improvements



Launchpad, the development framework created by Canonical, is under constant development.
If you have never used it, have a look at Jay's getting started and code management articles about it. If you know it already, you may be pleased to know that Launchpad has a …
[Read more]
Pimp My Workbench

Some weeks ago there was a request about adding a feature that keeps (or gets) datatypes of colums, which are connected via foreign keys, in sync. While we have added this to our ToDo list, I thought of doing some simple LUA exercises to give the user at least a funtion to check if the FKs in the model all have columns with matching datatypes.
As it turned out such tasks can be done quite easily using our GRT-shell. And by writing some functions you can add features to Workbenchs interface.

To get in touch with the shell/GRT environment inside Workbench click the tiny black prompt-window-icon in the top right area of workbench (or choose ‘View->Advanced->GRT Shell’ from the main menu).  Some items in the UI are swapped/added: the sidebar on the right side gets a new tab named ‘GRT Shell’ featuring some more tool-panes (GRT Tree, Modules, Inspector) and on the bottom part of the main window - where the editors …

[Read more]
How to unit-test code that interacts with a database

I got some interesting comments on my previous article about unit testing Maatkit, including echoes of my own conversion to the unit-testing religion. One of the objections I’ve heard a lot about unit-testing is how it’s impossible to test code that talks to a database. “It’s too hard,” they say. “Oh, it’s easy to test a module that calculates a square root, but a database? Way too much work!”

Note: As commenters have pointed out, I’m not necessarily using “unit” in the agreed-upon way here. Everything I say can be applied to ultra-pure unit testing too, but I go beyond that. I will hold fast to my assertions about mocking though *grin*

Is it really impossible or even hard?

I disagree. In one of my previous articles I said …

[Read more]
Showing entries 41 to 50 of 111
« 10 Newer Entries | 10 Older Entries »