📄 readme
字号:
Description: This method returns the current default database name specification, or None if the environment variables should be used. Environment variables won't be looked up. Syntax: set_defbase(base) Parameters: base - new default base name (string/None) Return type: string, None - previous default database name specification Exceptions raised: TypeError - bad argument type, or too many arguments Description: This method sets the default database name value for new connections. If None is supplied as parameter, environment variables will be used in future connections. It returns the previous setting for default host. 2.1.7. Module constants ----------------------- Some constants are defined in the module dictionary. They are intended to beused as parameters for methods calls. You should refer to PostgreSQL user manual for more information about them. These constants are: - large objects access modes, used by (pgobject.)locreate and (pglarge.)open: (pg.)INV_READ, (pg.)INV_WRITE, (pg.)INV_ARCHIVE - positional flags, used by (pglarge.)seek: (pg.)SEEK_SET, (pg.)SEEK_CUR, (pg.)SEEK_END. - version and __version__ constants that give the current version. 2.1.9. 2.1.10. Miscellaneous attributes The following methods return information about the current connection. - 2.2. pgobject description--------------------------- This object handle a connection to a PostgreSQL database. It embeds and hides all the parameters that define this connection, thus just leaving reallysignificant parameters in function calls. Some methods give direct access to the connection socket. They are specifiedby the tag [DA]. DO NOT USE THEM UNLESS YOU REALLY KNOW WHAT YOU ARE DOING. Ifyou prefer disabling them, set the -DNO_DIRECT option in the Python Setup file. Some other methods give access to large objects (refer to PostgreSQL usermanual for more information about these). if you want to forbid access to thesefrom the module, set the -DNO_LARGE option in the Python Setup file. These methods are specified by the tag [LO]. 2.2.1. query - executes a SQL command string -------------------------------------------- Syntax: query(command) Parameters: command - SQL command (string) Return type: pgqueryobject, None - result values Exceptions raised: TypeError - bad argument type, or too many arguments. ValueError - empty SQL query pg.error - error during query processing, or invalid connection Description: This method simply sends a SQL query to the database. If the query is an insert statement, the return value is the OID of the newly inserted row. If it is otherwise a query that does not return a result (ie. is not a some kind of SELECT statement), it returns None. Otherwise, it returns a pgqueryobject that can be accessed via the getresult method or printed. pgqueryobject methods --------------------- 2.2.1.1. getresult - gets the values returned by the query ------------------------------------------------------------- Syntax: getresult() Parameters: none Return type: list - result values Exceptions raised: SyntaxError - too many parameters pg.error - invalid previous result Description: This method returns the list of the values returned by the query. More information about this result may be get using listfields, fieldname and fiednum methods. 2.2.1.2. dictresult - like getresult but returns list of dictionaries --------------------------------------------------------------------- Syntax: dictresult() Parameters: none Return type: list - result values as a dictionary Exceptions raised: SyntaxError - too many parameters pg.error - invalid previous result Description: This method returns the list of the values returned by the query with each tuple returned as a dictionary with the field names used as the dictionary index. 2.2.1.3. listfields - lists the fields names of the previous query result ----------------------------------------------------------------------- Syntax: listfields() Parameters: none Return type: list - fields names Exceptions raised: SyntaxError - too many parameters pg.error - invalid previous result, or invalid connection Description: This method returns the list of names of the fields defined for the query result. The fields are in the same order as the result values. 2.2.1.4. fieldname, fieldnum - field name-number conversion --------------------------------------------------------- Syntax: fieldname(i) Parameters: i - field number (integer) Return type: string - field name Exceptions raised: TypeError - bad parameter type, or too many parameters ValueError - invalid field number pg.error - invalid previous result, or invalid connection Description: This method allows to find a field name from its rank number. It can be useful for displaying a result. The fields are in the same order than the result values. Syntax: fieldnum(name) Parameters: name - field name (string) Return type: integer - field number Exceptions raised: TypeError - bad parameter type, or too many parameters ValueError - unknown field name pg.error - invalid previous result, or invalid connection Description: This method returns a field number from its name. It can be used to build a function that converts result list strings to their correct type, using a hardcoded table definition. The number returned is the field rank in the result values list. 2.2.1.5 ntuples - return number of tuples in query object --------------------------------------------------------- Syntax: ntuples() Parameters: None Return type: integer Description: This method returns the number of tuples found in a query. 2.2.2. reset - resets the connection ------------------------------------ Syntax: reset() Parameters: None Return type: None Exceptions raised: TypeError - too many (any) arguments Description: This method resets the current database. 2.2.3. close - close the database connection -------------------------------------------- Syntax: close() Parameters: none Return type: None Exceptions raised: TypeError - too many (any) arguments Description: This method closes the database connection. The connection will be closed in any case when the connection is deleted but this allows you to explicitly close it. It is mainly here to allow the DB-SIG API wrapper to implement a close function. 2.2.4. fileno - returns the socket used to connect to the database ------------------------------------------------------------------ Syntax: fileno() Parameters: none Exceptions raised: TypeError - too many (any) arguments Description: This method returns the underlying socket id used to connect to the database. This is useful for use in select calls, etc. Note: This function depends on having a recent version of the database. See "-DNO_PQSOCKET" described above. 2.2.5. getnotify - gets the last notify from the server ------------------------------------------------------- Syntax: getnotify() Parameters: none Return type: tuple, None - last notify from server Exceptions raised: SyntaxError - too many parameters pg.error - invalid connection Description: This methods try to get a notify from the server (from the SQL statement NOTIFY). If the server returns no notify, the methods returns None. Otherwise, it returns a tuple (couple) (relname, pid), where relname is the name of the notify and pid the process id of the connection that triggered the notify. Remember to do a listen query first otherwise getnotify will always return None. 2.2.6. inserttable - insert a list into a table ----------------------------------------------- Syntax: inserttable(table, values) Parameters: table - the table name (string) values - list of rows values (list) Return type: None Exception raised: pg.error - invalid connection TypeError - bad argument type, or too many arguments Description: This method allow to quickly insert large blocks of data in a table: it inserts the whole values list into the given table. The list is a list of tuples/lists that define the values for each inserted row. The rows values may contain string, integer, long or double (real) values. BE VERY CAREFUL: this method doesn't typecheck the fields according to the table definition; it just look whether or not it knows how to handle such types. 2.2.7. putline - writes a line to the server socket [DA] -------------------------------------------------------- Syntax: putline(line) Parameters: line - line to be written (string) Return type: None Exceptions raised: pg.error - invalid connection TypeError - bad parameter type, or too many parameters Description: This method allows to directly write a string to the server socket. 2.2.8. getline - gets a line from server socket [DA] ---------------------------------------------------- Syntax: getline() Parameters: none Return type: string - the line read Exceptions raised: pg.error - invalid connection SyntaxError - too many parameters Description: This method allows to directly read a string from the server socket. 2.2.9. endcopy - synchronizes client and server [DA] ---------------------------------------------------- Syntax: endcopy() Parameters: none Return type: None Exceptions raised: pg.error - invalid connection SyntaxError - too many parameters Description: The use of direct access methods may desynchonize client and server. This method ensure that client and server will be synchronized. 2.2.10. locreate - creates of large object in the database [LO] --------------------------------------------------------------- Syntax: locreate(mode) Parameters: mode - large object create mode Return type: pglarge - object handling the postgres large object Exceptions raised: pg.error - invalid connection, or creation error TypeError - bad parameter type, or too many parameters Description: This method creates a large object in the database. The mode can be defined by OR-ing the constants defined in the pg module (INV_READ, INV_WRITE and INV_ARCHIVE). Please refer to PostgreSQL user manual for a description of the mode values. 2.2.11. getlo - builds a large object from given oid [LO] --------------------------------------------------------- Syntax: getlo(oid) Parameters: oid - oid of the existing large object (integer) Return type: pglarge - object handling the postgres large object Exceptions raised: pg.error - invalid connection TypeError - bad parameter type, or too many parameters ValueError - bad oid value (0 is invalid_oid) Description: This method allows to reuse a formerly created large object through the pglarge interface, providing the user have its oid. 2.2.12. loimport - import a file to a postgres large object [LO] ---------------------------------------------------------------- Syntax: loimport(name) Parameters: name - the name of the file to be imported (string) Return type: pglarge - object handling the postgres large object Exceptions raised: pg.error - invalid connection, or error during file import TypeError - bad argument type, or too many arguments Description: This methods allows to create large objects in a very simple way. You just give the name of a file containing the data to be use.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -