[pygda/introspection] Port the SELECT example



commit 56ad5b31e8cbd951ab7fd92e5f79dddea31fd2bb
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Apr 8 22:06:23 2011 +0200

    Port the SELECT example

 examples/gda/select.py |   45 ++++++---------------------------------------
 1 files changed, 6 insertions(+), 39 deletions(-)
---
diff --git a/examples/gda/select.py b/examples/gda/select.py
index caede19..64ad7a0 100755
--- a/examples/gda/select.py
+++ b/examples/gda/select.py
@@ -21,51 +21,23 @@ from gi.repository import Gda
 
 def main ():
 
-    data_source_name = "datasource_pygda_example_select11";
+    cnc_string = "HOST=localhost;PORT=5435;DB_NAME=glom_musiccollection211"
+    auth_string = "USERNAME=glom_default_developer_user;PASSWORD=glom_default_developer_password"
+    gda_connection = Gda.Connection.open_from_string("PostgreSQL", cnc_string, auth_string, Gda.ConnectionOptions.NONE)
 
-    #TODO: This should be Gda.Config.find_data_source().
-    data_source = Gda.Config.get_dsn_info(data_source_name);
-    if not data_source:
-        print "Creating the DataSource, because it does not exist yet.";
-
-        # Create it if it does not exist already:
-        data_source = Gda.DsnInfo();
-        data_source.name = data_source_name;
-        data_source.username = "murrayc";
-        data_source.password = "murraycpw";
-        data_source.description = "Data Source for libgdamm simple example.";
-        data_source.provider = "PostgreSQL";
-        # You must specify a database when using PostgreSQL, even when you want to create a database.
-        # template1 always exists with PostgreSQL.
-        # data_source.cnc_string = "DB_NAME=template1";
-        data_source.cnc_string = "DB_NAME=glom_example_smallbusiness_v114;HOST=localhost";
-
-        # TODO: Add save_data_source(data_source_info);
-        Gda.config_save_data_source(data_source.name, data_source.provider, data_source.cnc_string, data_source.description, data_source.username, data_source.password, False);
-
-    # Note that, if the server is not running, this can take a few minutes to fail: */
-    print "DEBUG: Before opening connection\n"
-    gda_connection = Gda.open_connection(data_source.name, data_source.username, data_source.password);
     print "DEBUG: After opening connection\n"
 
     if not gda_connection:
         print "Error: Could not open connection to ", data_source.name;
         return;
 
-    # Open database:
-    # This does not work with PostgreSQL: gda_connection.change_database("murrayc");
-
-    # Get data from a table:
-    command = Gda.Command("SELECT * FROM contacts");
-
     print "DEBUG: Before executing command\n"
-    data_model = gda_connection.execute_select_command(command);
+    data_model = gda_connection.execute_select_command("SELECT * FROM artists");
     print "DEBUG: After executing command\n"
 
     if not data_model:
         print "command execution failed.";
 
-    rows = data_model.get_n_rows();
     columns = data_model.get_n_columns();
     print "    Number of columns: ", columns;
 
@@ -73,15 +45,10 @@ def main ():
         print "      column ", i;
         print "        name=", data_model.get_column_title(i);
 
-        # Find out whether it's the primary key:
-        field = data_model.describe_column(i);
-        if field.get_primary_key(): #TODO: This should probably be wrapped as field.primary_key.
-            print "        (primary key)";
-
-        print "\n";
+    print "\n";
 
+    rows = data_model.get_n_rows();
     print "    Number of rows: ", rows;
-
     for row_index in range(rows):
         print "      row ", row_index;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]