Archive for the ‘mysql’ Category
Connecting to MySQL with ODBC on Mono
Friday, February 26th, 2010We had a visitor on #mono today who needed help with his homework. It seems that Reggie is happy to have forgotten everything about using ODBC to connect to MySQL. I was curious and feeling helpful, so I figured it out.
Install the MySQL ODBC driver
$ sudo apt-get install libmyodbc
You can also grab the package directly from MySQL
Configure the MySQL ODBC driver
ODBC looks in /etc/odbcinst.ini for driver configuration. In order to let it know about the MySQL ODBC libraries, append the following to your /etc/odbcinst.ini file:
[MySQL] Description = MySQL driver Driver = /usr/lib/odbc/libmyodbc.so Setup = /usr/lib/odbc/libodbcmyS.so CPTimeout = CPReuse =
Configure your DSN
If you expect that you will be using this database connection often, you may want to create a short name for it, so you don’t have to enter all of the parameters every time you want to connect. ODBC uses something called DSNs (Data Source Names, if I recall correctly) to make it easier on the user.
If you want to create a DSN, append something like the following to your /etc/odbc.ini file:
[myodbc3] Driver = MySQL Description = MySQL ODBC 3.51 Driver DSN Server = mysql Port = User = testuser Password = password Database = test Option = 3 Socket =
You will also need to update the ODBC Data Sources list near the top of the file to mention the new DSN:
[ODBC Data Sources] myodbc3 = MySQL ODBC 3.51 Driver DSN
C♯ ODBC connection example
Here is some example code to get you connected:
using System;
using System.Data;
using System.Data.Odbc;
class ODBCTest {
public static void Main(String[] args) {
// Connection string using explicit parameters
string ConStr = String.Format(
"DRIVER={0};SERVER={1};DATABASE={2};UID={3};PWD={4}",
"{MySQL}","mysql","test","testuser","password" );
// Connection string using DSN
// string ConStr = String.Format("DRIVER={0};DSN={1}",
// "{MySQL}","myodbc3");
//Create the connection object
var OdbcCon = new OdbcConnection( ConStr );
try {
Console.Write("Opening connection... ");
//open the database connection
if (OdbcCon.State == ConnectionState.Closed)
OdbcCon.Open();
Console.WriteLine("connection opened!");
} catch (OdbcException Ex) {
Console.WriteLine(Ex.Message);
} finally {
//close the database connection
OdbcCon.Close();
}
}
}
Well, that was an eventful day!
Saturday, September 12th, 2009*whew* I did a bunch of things yesterday. We took our kindergärtner to her first Friday at her new school (and were about 10 minutes tardy. oops). We then took our toddler to a nearby playground with swings and slides and let her expend some energy. After she had been sufficiently exercised, we walked back home, stopping at a coffee shop on the way. The baristo (you call male baristas “baristos,” right? :) ) recognized my MC Frontalot shirt and asked whether I had caught him the previous weekend at PAX. Unfortunately, I have not attended PAX since 2006, but I *did* purchase the tee directly from The Front himself ;)
When we got home, I worked a bit on an English Language parser implementation and then went to the University of Washington to meet with Emily Bender about getting in to the Professional Master’s program in Computational Linguistics. It all looks good, and I even got the good news that the GRE is no longer required!
After the meeting, I headed home and poked at the parser for a little while longer. I then picked Scarlet up from after-school care and brought her home. I then hopped in the car and drove toward Bellevue to meet up with Monty while he’s in town. I over-estimated the amount of time traffic would steal on my way to Bellevue, and had an extra hour to blow. So I dropped by building 41 and shot the IronPython bull with Dino. It turns out he’s got an android phone, too. I told him it was possible to put a debian chroot on it and that he should even be able to ‘apt-get install ironpython’ to his phone soon ;) We talked briefly about the CodePlex Foundation and Sam Ramji’s departure from The Evil Empire. Dino seems skeptical about the project. I don’t have enough information to have much of an opinion. However, it sounds like some folks I trust are involved, so I’m hopeful.
I left MS just in time to make it to the wrong address at the specified time. My phone had just enough juice to call Monty to get the right address and then use the navigation system to find my way there. I wasn’t able to make reservations at the place we intended to go for dinner until 8:15, so we went to the Barnes & Noble for a bit. They only had one NLP book in stock and the examples are all in Python. I should learn that language one of these days… As we were leaving the Pacific Place, Monty mentioned to me that he is on the advisory board for the CodePlex Foundation, and that they have been responsive enough to his input that they changed the Mission statement, at his recommendation, just one day before the Foundation was publicized. He feels that this is a very good direction for Microsoft to be heading.
My brother Chris was kind enough to watch the kids while we went out to dinner. Quick note: he recently graduated from UW with a BA in Electrical Engineering and is looking for work using his acquired knowledge, in case anyone needs one of those ;)
We met up with my wife, Hannah and our friends, Mike & Cynthia at our place. Monty graciously avoided mentioning the terrible state in which our apartment has recently found itself. The kids were super cute and polite and said hi/bye.
Over dinner we discussed building an android app (Monty has one, too ;) ) to automate the process of creating bounties for apps and getting folks to implement them. We also talked about MySQL and MariaDB, of course. Hannah and I recalled my time working for MySQL, Inc. on the MaxDB project and some subtle cultural differences we noticed while traveling. It was interesting getting the inside scoop about the Sun acquisition and some of the recent goings-on in the MySQL/Sun/Oracle world. I wasn’t aware, for instance, that the EU is balking on the merger because of monopoly concerns.
Writing Free Software – Part 9: Creating the wrapper script
Sunday, August 10th, 2008A previous post covered altering the install target so that it places the .exe assembly into the filesystem of the installer’s computer. In this part, we will cover creating the so-called “wrapper” script, which is the way recommended by the mono project’s application deployment guidelines to make the assembly executable on the system outside of the source distribution.
Return to the workplace
$ cd ~/src/greeting/
Create the wrapper script template
$ cat > greeting.in
#!/bin/bash
exec @RUNTIME@ @prefix@/lib/mono/@PACKAGE_NAME@/Greeting.exe "$@"
^D
Alter the configure.ac file to process the wrapper template
$ patch configure.ac
@@ -13,6 +13,7 @@ AC_CONFIG_FILES([ Makefile +greeting ]) AC_OUTPUT
^D^D
Alter the Makefile.am file to distribute the wrapper template
$ cat >> Makefile.am
bin_SCRIPTS = greeting
^D
Re-build the Makefile and wrapper script
$ autoconf && automake && ./configure
Test the install target
$ make && sudo make install
$ which greeting
/usr/local/bin/greeting
$ greeting ––number 8
Greetings, Neptune!
Conclusion
In this post, I gave an example of creating a simple wrapper shell script and using the autotools infrastructure to locate and use the system C# compiler and CLI runtime. This may not seem like much of a feat, but many systems have their binaries installed in weird locations and other quirks. The autotools system is able to detect and take care of these details without having the maintainer of the software create system-specific tweaks that would undoubtedly reduce the number of platforms on which the software would work.
Producing relocatable packages with the GNU build system
Saturday, September 29th, 2007I’ve recently found a need to create relocatable versions of some of my favorite libraries (produced, not-so-coincidentally by the GNU build system). You might find yourself asking “What is relocatable software, and why should I care?” Maybe I can help.
A piece of software is said to be “relocatable” when it does not rely on an absolute path in a filesystem in order to operate correctly. An example of this type of system is OS X’s .app directory/package framework.
As it currently stands, if I were to install iceweasel (or Firefox™) in /usr/local/mozilla/, but later realize there is more disk space available in /opt, I would be SOL. If mozilla were built as a relocatable package, however, moving /usr/local/mozilla/ to /opt/mozilla/ would not be a problem.
There are a couple of things standing in the way of this shiny new future.
1) In its current state, GNU autoconf accepts multiple absolute paths as argument values. In a relocatable package, all related software must be installed relative to a single point, referred to in autoconf nomenclature as the “prefix”. In a perfect world, all directories relative to the prefix would be further constrained as not to be beneath the prefix root. For example, defining the “bindir” as ${prefix}/../bin/ would be a no-no.
I have proposed a solution to this problem on the bug-autoconf list.
2) After a package is created in a relocatable way, how does one find said package once it has been moved?
The solution to this problem lies in the standardization of the use of pkg-config and subsequent modifications to the $PKG_CONFIG_PATH environment variable.
The first step is to ensure that your GNU build system includes a rule to generate a
Here are some examples from the Mono codebase. Note that configure.am is named configure.in in the mono codebase. Note further that I am scowling.
AC_OUTPUT([ Makefile mint.pc mono.pc mono-cairo.pc dotnet.pc mono-uninstalled.pc scripts/mono-nunit.pc ... ])
Here are a couple of examples of the contents of .pc.in files:
cjac@dom0:/usr/src/svn/mono/mono-1.2.5$ cat mint.pc.in
prefix=${pcfiledir}/../..
exec_prefix=${pcfiledir}/../..
libdir=${prefix}/lib
includedir=${prefix}/include/mono-@API_VER@
Name: Mono Interpreter
Description: Mono Interpreter Runtime
Version: @VERSION@
Requires: glib-2.0 gthread-2.0
Libs: -L${libdir} @export_ldflags@ -lmint @libmono_ldflags@
Cflags: -I${includedir} @libmono_cflags@
cjac@dom0:/usr/src/svn/mono/mono-1.2.5$ cat mono.pc.in
prefix=${pcfiledir}/../..
exec_prefix=${pcfiledir}/../..
libdir=${prefix}/@reloc_libdir@
includedir=${prefix}/include/mono-@API_VER@
Name: Mono
Description: Mono Runtime
Version: @VERSION@
Requires: glib-2.0 gthread-2.0
Libs: -L${libdir} @export_ldflags@ -lmono @libmono_ldflags@
Cflags: -I${includedir} @libmono_cflags@
Of particular importance in these files is the definition of ${prefix}, ${exec_prefix}, ${libdir} and ${includedir} relative to ${pcfiledir}. ${pcfiledir} is set at pkg-config run time as it iterates over the contents of the $PKG_CONFIG_PATH environment variable.
For example, if $PKG_CONFIG_PATH evaluates as “/home/cjac/opt/mono/lib/pkgconfig:/usr/lib/pkgconfig”, on the first iteration, ${pcfiledir} will store /home/cjac/opt/mono/lib/pkgconfig, and on the second iteration, ${pcfiledir} will store /usr/lib/pkgconfig.
So! Assuming I installed mono to ~/opt/mono, and I wanted to instead move it to /opt/mono, all I would need to do is the following:
$ sudo mv ~/opt/mono /opt $ export PKG_CONFIG_PATH="/opt/mono/lib/pkgconfig:$PKG_CONFIG_PATH"
And voila. All of my mono-related bits and all references to them have been moved. Independent of the absolute path to the mono package, the prefix can be determined in a consistent way:
$ pkg-config mono --variable=prefix
Comment away… I’ll try to get rid of some of the spam crowding my comment backlog…
A (round-about) story about Jeffry P. Bezos
Friday, January 26th, 2007The following is what i wrote on “43people.com” about the boss. I thought it was worth keeping in my own archives, since it’s actually a story about my life as it pertains to Mr. Bezos.
Back a few years ago, I was taking some classes down in Edmonds. The one I’m thinking of in particular was on the care and feeding of unix. We were using red hat linux 6.0 or some crufty version that wasn’t so crufty at the time.
Anyway, the prof didn’t require that we buy any books, but he made some suggestions. And he also suggested that we buy them on this new fangled “Internet” thing through a few of his friends down south in Seattle at this place called Amazon.com.
And thus was my introduction to O’Reilly and Associates. I soon thereafter bought a book called “Open Sources.” It quickly shaped my outlook on life and the way I viewed software, information and communication. The professor of the class told me that O’Reilly and Amazon got along quite well and that Amazon sold mostly technical books. I thought to myself “self, it might be fun to meet some of the folks at Amazon and maybe even take a job there.”
And that was about as far as I got on that train of thought before I hopped off and got distracted by the shiny bling of 3dfx and internet service providing. During this distracted period of my life (as opposed to the many and varied distracted periods that followed), I spent many an hour curled up in a comfy chair reading books published by Tim and friends that I bought from Amazon.
Then there was a period of weeping and gnashing of teeth when everyone got disillusioned by the whole humanity taking advantage of the VCs that funded development of the intarwebs thing.
I was happy to note that neither O’Reilly nor Amazon tanked during this period. This seemed like a well planned and well executed failure to fail.
After the fall of civilization, I found myself living in a social nexus called “Fey Abbey.” My fellow residents and the visitors were very supportive; I learned quite a bit about building intentional community, social networking, and the connectness of all things living.
I came up with some ideas about integrating these social networks with computational networks. I never implemented any of them to much extent, but shortly after I shared the ideas with the hive mind, sites like “friendster.com,” “tribe.net,” and “orkut.com” started showing up. Coincidence? Perhaps. Perhaps I had merely “tapped the zeitgeist” as Jeff is wont to say.
Either way, it taught me something about one’s involvement in community and the impact that such involvement triggers, in whatever direction the impact happens to travel.
But back to the story. I kept O’Reilly’s and Amazon.com’s success in mind as I delivered pizzas, sewed my wild oats, and dreamed of returning to the life of high technology.
I mentioned it to one of my confidantes and she said to me “get thee to a computery!” or something not unlike this, so, with her help and the help of my network of friends, I did. And shortly thereafter, but after more time than I would have liked at the time, I had an offer to take a contract working for Mr. Bezos and his company.
The contract went well; I learned a lot, and I like to think I imparted much wisdom, but rather than riding it out until the bitter end, I took some time to train with some Europeans on how to make software that lasts much longer than anyone would have expected (and maybe hoped).
I returned to the doors of Amazon.com barely a year later with resume in hand, some ideas that I wanted to implement, and a great deal more experience. The folks with whom I interviewed fought hard to get me on their team, hinting that the group would be getting close attention from senior members of staff.
So here I am, working with a crack team to build the pet projects of “senior members of amazon staff.” It’s challenging work, but it’s work that I’ve been intending to get done for a few years now. If I read him right, I think Jeff has many of the same ideas about software and perhaps the world as do I. Perhaps I’ll talk to him about it tomorrow night…
Bind configuration cleaned up
Friday, December 29th, 2006Okay. That wasn’t so bad.
Now I need to find out whether people are querying colliertech.org or ns1.colliertech.org and ns2.colliertech.org. If colliertech.org is still getting the brunt of the requests, I need to find out how I misconfigured bind and then fix it.
If the requests have started flowing to ns1.colliertech.org (66.152.65.10) and ns2.colliertech.org (66.152.65.11) rather than hitting the old (and now deprecated) name server at colliertech.org (216.39.139.201).
If you have advice, let me know.
Also, I fixed the wiki. I couldn’t migrate to the new php5/mysql5 stack and svn version of mediawiki on the other machine, so we’re back up on the old hardware until I find the time to migrate. One of these days :)
EricLippert01.wmv (video/x-ms-wvx Object)
Friday, November 24th, 2006EricLippert01.wmv (video/x-ms-wvx Object)
So… a while ago, I took
arjen_lentz to Microsoft to meet with
eric_lippert and talk about MySQL and Microsoft together-workingness. Eric talked about his work on LiNQ (if that’s how it’s spelled) and I took pictures. I didn’t really follow, but I bet the data folks in the audience will find this video interesting.
So go! Watch! :)
My former CEO answers questions on Slashdot
Tuesday, October 24th, 2006It was my pleasure to work with Mårten Mickos, CEO of MySQL for about a year during 2005 and 2006. I was astounded by how involved he is with the employees and how well he keeps abreast of the goings-on in the company. He seems to be of the rare set who are not only strong supporters and evangelizers of the company and software, but are also technically familiar with it. With great folks like Mårten, Brian, Arjen, Zack and Ulf, MySQL AB has been and continues to be one of the most important Open Source companies that exists.
Go read the slashdot article here:
http://interviews.slashdot.org/interviews/06/10/20/1325244.shtml
spamassassin tls plugin
Monday, August 28th, 2006Anybody got a tls plugin for spamassassin? Something that will check to see whether incoming mail is signed by a certificate known to and trusted by spamd?
Second Life on Linux
Sunday, August 13th, 2006Someone should do something with these, or I’m going to do it myself.

