/*
		msql.library simple example
		©1998 Christophe Sollet (cfc@iname.com)

		This simple example list existing database on
		a mSQL database engine running on the local host.
*/

#include <exec/types.h>
#include <proto/exec.h>
#include <proto/msql.h>
#include <libraries/msql.h>
#include <stdio.h>

struct Library *MsqlBase;

main()
{
	struct MsqlConnection *co;
	m_result *mre;
	m_row	mro;
	if(MsqlBase = OpenLibrary("msql.library", 1))   /* Open the library */
	{
        /* Before doing any msql operation, we need a valid MsqlConnection structure */
		if(co = MsqlAllocConnection())
		{
            /* Now we'll attempt a connection on a local mSQL database engine */
			if(MsqlConnect(co, "localhost"))
			{
                /* Gets current DB list */
				mre = MsqlListDBs(co);
				if(mre)
				{
					printf("DB(s):\n");
                    /* Now display DB list */
					while(mro = MsqlFetchRow(co, mre))
					{
						printf("%s\n", *mro);
					}
					MsqlFreeResult(co, mre);
				} else
                {
                    printf("ListDBs failed\n");
                    printf("%s\n", MsqlGetErrMsg(co)); /* Display err message */
                }
				MsqlClose(co);
			} else
            {
                printf("Connection failed\n");
                printf("%s\n", MsqlGetErrMsg(co));
            }
			MsqlFreeConnection(co);
		} else printf("Alloc failed\n");
		CloseLibrary(MsqlBase);
	}
}
