- Details
One of my clients runs Joomla with the VirtueMart extension (an online shop component). To make it simpler to look after, I thought about writing an application that would update prices pulled from some source or other.
The application uses DB_Linq, a LINQ provider for MySQL, Oracle and PostgreSQL. Unfortunately DB_Linq currently has no documentation at all. I did find a few scraps of information on the Primary Objects site. I used version 0.18, which is deprecated, because with 0.19 I had trouble generating the LINQ classes.
Version 0.18 had a problem of its own...
DbMetal failed:System.ArgumentException: magma string must not be empty
It turned out that there is a problem when table names in the database contain two underscores next to each other.
Naturally I dug around in the code a little and fixed it:
//\DbLinq-0.18\src\DbLinq\Language\Implementation\AbstractWords.cs, line 139
public virtual IList<string> GetWords(string text)
{
text = text.Replace("__", "_"); //turns two underscores into one
Now I could start enjoying LINQ against a MySQL database.
Here is, step by step, what you need to do in order to poke around a MySQL database comfortably.
- Download DB_Linq
- Generate the model classes from the database structure. A single file will be created, named after the database
dbmetal /server:1.2.3.4 /user:dbuser /password:password /provider:MySql /database:people /language:C#
- That is all :)
The classes are ready, so you can start working against the database.
Reading data from the database (SELECT).
public ObservableCollection GetProducts()
{
using (var connection = new MySqlConnection("server=server.pl;user id=user; password=secret; database=mydb"))
{
connection.Open();
using (var dataContext = new BazaDataContext(connection))
{
var items = from s in dataContext.JoSVMProduct
join pc in dataContext.JoSVMProductPrice on s.ProductID equals pc.ProductID
orderby s.ProductName ascending
select new ProduktVm
{
ProductId = s.ProductID,
ProductSku = s.ProductSku,
ProductName = s.ProductName,
ProductPrice = pc.ProductPrice,
ProductFullImage = s.ProductFullImage,
};
var collection = new ObservableCollection();
foreach (var c in items)
collection.Add(c);
return collection;
}
}
}
In the example above I fetch product and price data and build myself an observable collection. ProduktVm is my own intermediate class.
Updating data in the database (UPDATE).
using (var conn = new MySqlConnection("server=server.pl;user id=user; password=secret; database=mydb"))
{
conn.Open();
using (var context = new BazaDataContext(conn))
{
var items = from pc in context.JoSVMProductPrice
where pc.ProductID == 1
select pc;
var i = items.First();
i.ProductPrice = -1;
context.SubmitChanges();
}
}
Adding data to the database (INSERT).
using (PeopleDataContext context = new PeopleDataContext(connection))
{
// Create a LINQ to SQL class to fill the properties.
Person person = new Person();
person.FirstName = txtFirstName.Text;
person.LastName = txtLastName.Text;
person.Age = Convert.ToInt32(txtAge.Text);
context.Person.InsertOnSubmit(person);
context.SubmitChanges();
}
I am not doing any inserts in my application yet, so the example comes from Primary Objects
One last thing: VMManager was supposed to read its data from Excel, but unfortunately I found no working way of getting data out of a worksheet. I saved the sheet as a tab-separated text file, and that kind of data can be read without any trouble.
- Details
Everyone who ought to have heard it first already has, so now you may hear it too: I am engaged :D And it happened on 3 January 2010, in front of the Łazienki Palace (the Palace on the Isle) in Warsaw.
- Details
Yesterday a friend of mine published the first version of the Bieduino project, that is "an Arduino for the poor". I prepared the board layout (because I know Eagle very well) based on the Metaboard, and Kamil did the rest.
I am in the middle of preparing the next version, 1.1, so if you have any opinions or suggestions do leave a comment here or on Kamil's blog.
- Details
Today my friend Rafał left a comment on my previous attempt at getting Joomla to work with Windows Live Writer. He gave me a link to the very post I had linked to myself :D Even so I tried again, and found another interesting post on the MYGUIDE blog. In that post I read about Fiddler, a very nice application for eavesdropping on whatever any application sends to a server. Krzysiek Sopyła demonstrated it at one of the OLMUG meetings; I had not had a chance to play with it, and now the chance presented itself.
I listened in on the conversation between WLW and my Joomla, and this is what I saw:
8b <br /> <b>Notice<!--b>: Undefined index: more_text in <b>/.../www/plugins/xmlrpc/metaweblog.php<!--b> on line <b>213<!--b><br /> 8e <br /> <b>Notice<!--b>: Undefined index: mt_text_more in <b>/.../www/plugins/xmlrpc/metaweblog.php<!--b> on line <b>217<!--b><br /> 87 <br /> <b>Notice<!--b>: Undefined variable: row in <b>/.../www/plugins/xmlrpc/metaweblog.php<!--b> on line <b>261<!--b><br /> 94 <br /> <b>Notice<!--b>: Trying to get property of non-object in <b>/.../www/plugins/xmlrpc/metaweblog.php<!--b> on line <b>261<!--b><br /> 80 xml version="1.0"?> <methodResponse> <params> <param> <value><string>341<!--string><!--value> <!--param> <!--params> <!--methodResponse> 0
That made everything clear. Metaweblog was a little "rough around the edges", and wherever warnings were not switched off on the server, extra messages appeared and broke the structure of the XML. Strictly speaking I ought to have warnings switched off (so that if something goes wrong a visitor does not get to read more or less interesting messages), but I often use my site as a testing ground, and that is why things are as they are.
I fixed a few lines in metaweblog.php and now I can write in WLW. Unfortunately automatic image upload does not work (I did set the FTP options in WLW), nor does downloading the theme or all of the posts straight from the site. Getting that working would mean fixing another dozen or so lines.
P.S.
I also recommend the WLW plugin called Dynamic Template. It lets you add templates of your own, for instance one that splits an article into an intro and the rest, with a "Read more..." break in between :) Unfortunately, when you edit the post again the "Read more" turns into a comment and no longer does its job - ah, interoperability, or rather the lack of it...
- Details
On the occasion of the Birth of Jesus Christ, I wish you all much joy in your everyday work, much good fortune in your programming, God's grace in solving algorithmic problems, and a great deal of love for your neighbour.
- Details
On 15 December 2009, the Faculty of Mathematics and Computer Science at the University of Warmia and Mazury in Olsztyn will host the Windows 7 Community Launch. The event is organised by the Olsztyn community gathered around the professional group OLMUG and the academic Eastgroup.pl. Its aim is to introduce those attending to the newest version of Microsoft's operating system, Windows 7.
Two presentations will be given during the meeting:
- What's new in Windows 7, led by Kamil Lemański and Daniel Plawgo,
- Windows 7 for developers, led by Bartłomiej Zass of Microsoft.
Enthusiasts, experts, IT staff and anyone else are all welcome - everybody with an interest in the subject will be glad they came.
The meeting takes place at ul. Żołnierska 14, room 49. We start at 17:00!
Places are limited, so it is worth registering today through the MS-Groups portal. Registration and attendance are free! There are prizes waiting for those who take an active part.
- Details
I have a few coins for sale:
Bolesław II the Bold 1058 1079
50 ZŁ PRL 1981
John Paul II sold
10000 ZŁ PRL 1987
Solidarność 1980 1990
10000 Zł RP 1990
Whoever buys the lot gets the box thrown in :)
- Details
A new company has just come into being - not actually registered yet, but it will be before long. It is called CrystalCode Studio. At the moment we are building a framework and a CMS of our own.
- Details
I have just fixed how JoomFish works with Joomla's own RSS feed handling. From now on every page with a list of articles offers an RSS feed of those articles.
- Details
I finally built myself a programmer!!!
Loading drivers on a 64-bit system
Unfortunately my Windows 7 64-bit insists that drivers be signed, and these are not. I read up on it and found that to sign the drivers myself I would first need a VeriSign certificate at $399 a year :D so I gave that up.
2009-12-16: I have just learned that the certificate can be had for $99 a year (that is 284.65 PLN - still too much for a small non-commercial project), by following the link on the Winqual Help page.
There are plenty of recipes on the internet for getting unsigned drivers to load, but almost none of them worked here, and some even did the system a bit of damage (to the point where practically no driver other than Microsoft's own would load at all). The only thing that did work was Driver Signature Enforcement Overrider 1.3b.
To make the system load the libusb drivers, after installing them you have to sign every sys and dll file (the Sign a System File option in DSEO):
c:\windows\system32\drivers\libusb0.sys
c:\windows\system32\libusb0.dll
c:\windows\syswow64\libusb0.dll
Installing further devices can, however, overwrite those signed drivers with unsigned versions, so I did it slightly differently. I signed the files before I installed the device:
bin\win-driver\libusb_0.1.12.1\libusb0.dll
bin\win-driver\libusb_0.1.12.1\libusb0.sys
bin\win-driver\libusb_0.1.12.1\libusb0_x64.dll
bin\win-driver\libusb_0.1.12.1\libusb0_x64.sys
That way the drivers do load :D (p.s. people write that you have to turn UAC off; I turned it off before doing all this and switched it back on once everything worked - and it still works)
A USB PID of my own
One more thing. I found out that FTDI hands out unique PIDs within its own VID to its customers. I thought I would be clever and build my own programmer with my own drivers. I wrote them an email. All I had to give was
- my surname
- a company name
- a country
- an email address
and I was given eight PIDs of my own, free of charge. :D I wanted to use one of them for the programmer, but the driver signing question stopped me (and while I was at it I noticed that avrdude would not see my programmer anyway)
USBasp
There will be no photographs of the programmer for now because I have no camera, but it looks roughly like the one modelled in the previous post.
I used the software in version usbasp.2009-02-28 from the USBasp author's site. For programming I use avrdude. I write the programs in Code::Blocks (in the post-build steps I added
avrdude -q -p m8 -c usbasp -e -U flash:w:$(TARGET_OUTPUT_FILE).hex
so that the moment it compiles, the software lands in the microcontroller) together with WinAVR-20090313.
I am not going to repeat the assembly instructions, because everything is on the author's site and, in Polish, on Mirley's site
If anyone has questions, do get in touch :)
Debugging over RXD/TXD
The author of the programmer allowed for sending data using the UART in the programmer's microcontroller, but so far that feature is not supported. I am in the middle of modifying the firmware and writing an application to make use of it.
At the moment I can already switch LEDs on and off from an application on the PC :D Now I have to learn to drive the UART.
AVRUSBBoot vs BootloadHID
To make it easy to modify the software in the programmer, I decided to put a bootloader into it.
The trouble with AVRUSBBoot is that it needs drivers (libusb - the signing problem) and that it uses the same VID and PID as USBasp, so Windows installs the USBasp drivers straight away and the loader cannot see the device (because it checks not only the VID and PID but also the device name and vendor)
BootloadHID does a far better job. It needs no drivers at all - it uses the ones built into Windows.
In both cases the principle is the same. The bootloader is placed at the end of the flash memory and the fuse bits are set so that execution starts there after the microcontroller is reset. If the right pins are in the right state after a reset (the so-called bootLoaderCondition), the bootloader code runs and the computer sees the device as AVRUSBBoot or as a USB input device, as the case may be. The loader then writes the real firmware into the microcontroller.
Do remember that when you change bootLoaderCondition you also have to fix the pull-up settings for those pins (if the condition is a pin shorted to ground). I used the Slow SCK jumper from USBasp as the condition for entering the bootloader.
static inline void bootLoaderInit(void)
{
PORTC = (1 << PC2); /* activate pull-up for key */
_delay_us(10); /* wait for levels to stabilize */
}
#define bootLoaderCondition() ((PINC & (1 << PC2)) == 0)
2009-11-22:
Unfortunately, using a bootloader in the programmer did not work out. The programmer itself refuses to work properly.