Exemple #1
0
func listDrivers()
{
	fmt.Printf ( "Listing Drivers (odbcinst -q -d) >>\n" );

	var x int;
	var driver, attr string;

	direction := godbc.GS_FETCH_FIRST;

	for
	{
		x, driver, attr = env.GS_Drivers ( direction );

		if ( ! godbc.GS_Succeeded ( x ) )
		{
			break;
		}

		direction = godbc.GS_FETCH_NEXT;

		fmt.Printf ( "Driver: %s Attr: %s\n", driver, attr );

		if x == godbc.GS_SUCCESS_WITH_INFO
		{
			fmt.Printf ( "\tdata truncation\n" );
		}
	}
}
Exemple #2
0
func extractError ( function string
	, handle * godbc.GS_HANDLE
	, handleType int )
{
	var x, nativeError int;
	var sqlState, messageText string;
	recNumber := 1;

	fmt.Printf ( "The driver reported the following diagnostics whilst running %s\n\n", function );

	for
	{
		x, sqlState, nativeError, messageText = handle.GS_GetDiagRec ( handleType, recNumber );

		recNumber++;

		if ( godbc.GS_Succeeded ( x ) )
		{
			fmt.Printf ( "%s:%d:%d:%s\n", sqlState, recNumber, nativeError, messageText );
		}
		else
		{
			break;
		}
	}
}
Exemple #3
0
func listDataSources()
{
	fmt.Printf ( "Listing Data Sources (odbcinst -q -s) >>\n" );

	var x int;
	var dsn, desc string;

	direction := godbc.GS_FETCH_FIRST;

	for
	{
		x, dsn, desc = env.GS_DataSources ( direction );

		if ( ! godbc.GS_Succeeded ( x ) )
		{
			break;
		}

		direction = godbc.GS_FETCH_NEXT;

		fmt.Printf ( "DSN: %s Desc: %s\n", dsn, desc );

		if x == godbc.GS_SUCCESS_WITH_INFO
		{
			fmt.Printf ( "\tdata truncation\n" );
		}
	}
}
Exemple #4
0
func listTables()
{
	stmt.GS_Tables ( "", 0, "", 0, "", 0, "TABLE", godbc.GS_NTS );

	_, columns := stmt.GS_NumResultCols();

	fmt.Printf ( "Number of columns: %d\n", columns );

	for row := 1;; row++
	{
		x := stmt.GS_Fetch();

		if ! godbc.GS_Succeeded ( x )
		{
			break;
		}

		fmt.Printf ( "Row %d => ", row );

		for i := 1; i <= columns; i++
		{
			ret, indicator, columnValue := stmt.GS_GetData_String ( i );

			if godbc.GS_Succeeded ( ret )
			{
				if indicator == godbc.GS_NULL_DATA
				{
					columnValue = "NULL";
				}

				fmt.Printf ( "Col %d: \"%s\" ", i, columnValue );
			}
		}

		fmt.Printf ( "\n" );
	}
}
Exemple #5
0
func connect()
{
	x, str := dbc.GS_DriverConnect ( 0, "DSN=dsn1mysql;UID=root;PWD=password", godbc.GS_DRIVER_COMPLETE );

	if ( godbc.GS_Succeeded ( x ) )
	{
		fmt.Printf ( "Connected. Details: %s\n", str );
	}
	else
	{
		fmt.Printf ( "Unable to connect. Check the login credentials provided in the code.\n" );
		extractError ( "connect()", dbc, godbc.GS_HANDLE_DBC );
		os.Exit (1);
	}
}