Sophie

Sophie

distrib > Mandriva > 10.2 > i586 > media > contrib > by-pkgid > 6338fb0a19fe7b6baeca7897c46a9ee3 > files > 85

knoda-0.7.2-2mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML
><HEAD
><TITLE
>How to execute a query</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="The knoda scripting tutorial"
HREF="index.html"><LINK
REL="UP"
TITLE="Tips and tricks"
HREF="chapter5.html"><LINK
REL="PREVIOUS"
TITLE="Tips and tricks"
HREF="chapter5.html"><LINK
REL="NEXT"
TITLE="How to create a table"
HREF="createtable.html"><META
HTTP-EQUIV="Content-Style-Type"
CONTENT="text/css"><LINK
REL="stylesheet"
HREF="common/kde-common.css"
TYPE="text/css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=iso-8859-1"><META
HTTP-EQUIV="Content-Language"
CONTENT="en"><LINK
REL="stylesheet"
HREF="common/kde-localised.css"
TYPE="text/css"
TITLE="KDE-English"><LINK
REL="stylesheet"
HREF="common/kde-default.css"
TYPE="text/css"
TITLE="KDE-Default"></HEAD
><BODY
CLASS="SECTION"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#AA0000"
VLINK="#AA0055"
ALINK="#AA0000"
STYLE="font-family: sans-serif;"
><DIV
CLASS="logoheader"
><A
HREF="http://www.kde.org/"
></A
></DIV
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>The knoda scripting tutorial</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="chapter5.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 5. Tips and tricks</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="createtable.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECTION"
><H1
CLASS="SECTION"
><A
NAME="QUERYDATA"
></A
>5.2. How to execute a query</H1
><P
>Result queries (SELECT statement) return data when they are executed.
<DIV
CLASS="EXAMPLE"
><HR><A
NAME="AEN440"
></A
><P
><B
>Example 5-2. Execute a "SELECT" query</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>   1&nbsp;horst@horstnotebook:~&#62; python
   2&nbsp;Python 2.2.2 (#1, Mar 17 2003, 15:17:58)
   3&nbsp;[GCC 3.3 20030226 (prerelease) (SuSE Linux)] on linux2
   4&nbsp;Type "help", "copyright", "credits" or "license" for more information.
   5&nbsp;&#62;&#62;&#62; from hk_classes import *
   6&nbsp;d&#62;&#62;&#62; dr=hk_drivermanager()
   7&nbsp;&#62;&#62;&#62; con=dr.new_connection("mysql")
   8&nbsp;&#62;&#62;&#62; con.set_password("secret")
   9&nbsp;&#62;&#62;&#62; con.connect()
  10&nbsp;1
  11&nbsp;&#62;&#62;&#62; db=con.new_database("exampledb")
  12&nbsp;&#62;&#62;&#62; query=db.new_resultquery()
  13&nbsp;&#62;&#62;&#62; query.set_sql("SELECT * FROM authors")
  14&nbsp;1
  15&nbsp;&#62;&#62;&#62; query.enable()
  16&nbsp;SQL : SELECT  *  FROM  authors
  17&nbsp;1</PRE
></TD
></TR
></TABLE
><HR></DIV
>


Many queries, such as data definition queries, don't return data.  They only report whether execution of the
query was successful or whether it failed.
<DIV
CLASS="EXAMPLE"
><HR><A
NAME="AEN443"
></A
><P
><B
>Example 5-3. Execute an action query</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>   1&nbsp;horst@horstnotebook:~&#62; python
   2&nbsp;Python 2.2.2 (#1, Mar 17 2003, 15:17:58)
   3&nbsp;[GCC 3.3 20030226 (prerelease) (SuSE Linux)] on linux2
   4&nbsp;Type "help", "copyright", "credits" or "license" for more information.
   5&nbsp;&#62;&#62;&#62; from hk_classes import *
   6&nbsp;d&#62;&#62;&#62; dr=hk_drivermanager()
   7&nbsp;&#62;&#62;&#62; con=dr.new_connection("mysql")
   8&nbsp;&#62;&#62;&#62; con.set_password("secret")
   9&nbsp;&#62;&#62;&#62; con.connect()
  10&nbsp;1
  11&nbsp;&#62;&#62;&#62; db=con.new_database("exampledb")
  12&nbsp;&#62;&#62;&#62; query=db.new_actionquery()
  13&nbsp;&#62;&#62;&#62; query.set_sql("CREATE TABLE `another new table` ( `id` BIGINT(1) NOT NULL AUTO_INCREMENT , `name` BIGINT, PRIMARY KEY ( `id` ) )")
  14&nbsp;&#62;&#62;&#62; query.execute()
  15&nbsp;CREATE TABLE `another new table` ( `id` BIGINT(1) NOT NULL AUTO_INCREMENT , `name` BIGINT, PRIMARY KEY ( `id` ) )
  16&nbsp;1</PRE
></TD
></TR
></TABLE
><HR></DIV
>
&#13;</P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="chapter5.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="createtable.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Tips and tricks</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="chapter5.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>How to create a table</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>