From pythonTutor at venix.com Wed Nov 3 21:41:52 2004 From: pythonTutor at venix.com (Lloyd Kvam) Date: Wed Nov 3 21:42:39 2004 Subject: [DB-SIG] Re: [Tutor] mysql formatting In-Reply-To: References: Message-ID: <1099514511.19711.45.camel@laptop.venix.com> I checked our programming. We add the % for like to the parameter! s = 'update doorman set status = %s where in_id = %s and out_address like %s' cursor.execute(s, (new_status, inside_id, '%'+out_address+'%')) On Wed, 2004-11-03 at 14:30, Marilyn Davis wrote: > Darn me. > > I still don't have it right. > > As a reminder, here's my method: > > def execute_mysql(self, this, *args): > if log.level & log.sql: > log.it('About to execute:' + this + '<-->' + repr(args)) > try: > self.cursor.execute(this, args) > except _mysql_exceptions.Warning, msg: > log.it('Mysql Warning: ' + str(msg)) > except _mysql_exceptions.OperationalError, msg: > print "Are you using the right data base? Try changing > /b/local/doorman/configure.py TESTING = 0" > raise > > > Yes, Danny is right that the database name must be hard-coded: > > > s = 'update doorman set status = "%s" where in_id = %s and out_address like > "%%%s%%"' > my_connection.execute_mysql(s, new_status, inside_id, out_address) > > > Doing that eliminates the traceback. But the update doesn't happen > and in mysql's log I see: > > update doorman set status = "'MOVED'" where in_id = '60' and > out_address like "%'courier-imap-admin@lists.sourceforge.net'%"; > > So I still have too many 's. > > Here I try Lloyd's idea and take all the quotes out of my format: > > s = 'update doorman set status = %s where in_id = %d and out_address like > %%%s%%' > my_connection.execute_mysql(s, new_status, int(inside_id), out_address) > > > inside_id is "60", as a string. I figured I have better luck passing > int(inside_id). But: > > File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py", line 33, in > defaulterrorhandler > raise errorclass, errorvalue > TypeError: int argument required > > That sure stumps me. > > So I try %s: > > s = 'update doorman set status = %s where in_id = %s and out_address like > %%%s%%' > my_connection.execute_mysql(s, new_status, inside_id, out_address) > > Gets me: > > _mysql_exceptions.ProgrammingError: (1064, "You have an error in your > SQL syntax; check the manual that corresponds to your MySQL server > version for the right syntax to use near > '%'courier-imap-admin@lists.sourceforge.net'%' at line 1") > > Maybe it has something to do with unpacking the tuple? So I give a > fancy version a try, back to fiddling with escapes: > > def execute_mysql(self, this, *args): > caller = 'self.cursor.execute(\"%s\"' % this > for each in args: > caller += ", " + each > caller += ')' > print caller > try: > exec(caller) > # self.cursor.execute(this, args) > except _mysql_exceptions.Warning, msg: > log.it('Mysql Warning: ' + str(msg)) > except _mysql_exceptions.OperationalError, msg: > print "Are you using the right data base? Try changing > /b/local/doorman/configure.py TESTING = 0" > raise > > and I go back to this call, afterall, it has "%s", %s, and "%%%s%%", > trying everything: > > s = 'update doorman set status = "%s" where in_id = %s and out_address like > "%%%s%%"' > my_connection.execute_mysql(s, new_status, inside_id, out_address) > > > self.cursor.execute("update doorman set status = "%s" where in_id = %s and > out_address like "%%%s%%"", MOVED, 60, courier-imap-admin@lists.sourceforge.net) > ^ > SyntaxError: invalid syntax > > > I don't know. This is very hard! > > Maybe I should use MySQLdb.escape_string on my addresses and be happy > with that? Maybe this is why it's not documented, maybe it's not so > robust. > > Thank you for your help and thought. > > Marilyn > -- Lloyd Kvam Venix Corp From farcepest at gmail.com Wed Nov 3 22:46:26 2004 From: farcepest at gmail.com (Andy Dustman) Date: Wed Nov 3 22:46:28 2004 Subject: [DB-SIG] Re: [Tutor] mysql formatting In-Reply-To: <1099514511.19711.45.camel@laptop.venix.com> References: <1099514511.19711.45.camel@laptop.venix.com> Message-ID: <9826f3800411031346314acbbf@mail.gmail.com> On Wed, 03 Nov 2004 15:41:52 -0500, Lloyd Kvam wrote: > I checked our programming. We add the % for like to the parameter! 1) Use %s for all parameter placeholders, regardless of type. 1a) You can use %(key)s for a placeholder if you pass a dictionary as the parameters. 2) Do not put additional quotes around the placeholder. 3) Do not use placeholders for things like table or column names; they only work for column values. 4) If you use % anywhere in your query (i.e. x LIKE 'foo%'), you must double it (%%, i.e. x LIKE 'foo%%'); it is not necessary to do this to your parameter values. https://sourceforge.net/forum/forum.php?thread_id=1075920&forum_id=70461 http://cvs.sourceforge.net/viewcvs.py/*checkout*/mysql-python/MySQLdb/doc/MySQLdb.txt?rev=HEAD -- Computer interfaces should never be made of meat. From joe at goldthwaites.com Wed Nov 3 22:51:02 2004 From: joe at goldthwaites.com (Joe Goldthwaite) Date: Wed Nov 3 22:51:10 2004 Subject: [DB-SIG] mxODBC.ProgrammingError: ('37000', 8501, "[Microsoft][ODBC SQL Server Driver][SQL Server]MSDTC on server 'xxxxx' is unavailable.", 4612) Message-ID: <002a01c4c1ef$36aa9530$7264a8c0@jgoldamd> I suspect I'm not going to get a happy answer on this one. I ran into it during the final testing of some major structural changes in my application. I'm using SQL server as my database. I had originally built some data tables for reporting and was storing them in the main database used by our JDE application. Due to some additional requirements for other reporting databases, I pulled the tables out and put them in their own database on a separate server. I then used Microsoft SQL servers ability to link tables to access the raw data from the JDE database and pull the data into the reporting database. To do this, I specify the fully qualified table name in my stored procedure. For example, to reference the F0901 table in the JDE_PRODUCTION database on our JDEENT server, I have to reference it as JDEENT.JDE_PRODUCTION.PRODDTA.F0901. JDEENT is the server name, JDE_PRODUCTION is the database name and PRODDTA is the table owner. If I execute the stored procedure or one of the individual queries from within Microsoft's SQL Query Analyzer, it works fine. When I try to execute the exact same SQL statement from the cursor.execute function, I get the above MSDTC error. MSDTC stands for Microsoft Distributed Transaction Coordinator. I suspect that the MS Query Analyzer is doing something different that allows it to reference linked tables that the mxODBC code does not. I'm hoping that someone knows about some setting or something that enables the use of linked tables in mxODBC. I'm not optimistic though. It's a bummer that I ran into this at the END of all my changes... Thanks for reading, Joe Goldthwaite From mal at egenix.com Thu Nov 4 09:28:16 2004 From: mal at egenix.com (M.-A. Lemburg) Date: Thu Nov 4 09:28:12 2004 Subject: [DB-SIG] mxODBC.ProgrammingError: ('37000', 8501, "[Microsoft][ODBC SQL Server Driver][SQL Server]MSDTC on server 'xxxxx' is unavailable.", 4612) In-Reply-To: <002a01c4c1ef$36aa9530$7264a8c0@jgoldamd> References: <002a01c4c1ef$36aa9530$7264a8c0@jgoldamd> Message-ID: <4189E820.4010202@egenix.com> Copying the error message here: [Microsoft][ODBC SQL Server Driver][SQL Server]MSDTC on server 'xxxxx' is unavailable.", 4612) Joe Goldthwaite wrote: > I suspect I'm not going to get a happy answer on this one. I ran into it > during the final testing of some major structural changes in my application. > I'm using SQL server as my database. I had originally built some data > tables for reporting and was storing them in the main database used by our > JDE application. Due to some additional requirements for other reporting > databases, I pulled the tables out and put them in their own database on a > separate server. I then used Microsoft SQL servers ability to link tables > to access the raw data from the JDE database and pull the data into the > reporting database. > > To do this, I specify the fully qualified table name in my stored procedure. > For example, to reference the F0901 table in the JDE_PRODUCTION database on > our JDEENT server, I have to reference it as > JDEENT.JDE_PRODUCTION.PRODDTA.F0901. JDEENT is the server name, > JDE_PRODUCTION is the database name and PRODDTA is the table owner. Note that there's a limit on the length of column names in SQL: mxODBC uses a 37 character limit which is what ANSI SQL defines. I don't that's a problem here, though, since you'd get a warning from the database in case of truncations. > If I execute the stored procedure or one of the individual queries from > within Microsoft's SQL Query Analyzer, it works fine. When I try to execute > the exact same SQL statement from the cursor.execute function, I get the > above MSDTC error. MSDTC stands for Microsoft Distributed Transaction > Coordinator. > > I suspect that the MS Query Analyzer is doing something different that > allows it to reference linked tables that the mxODBC code does not. I'm > hoping that someone knows about some setting or something that enables the > use of linked tables in mxODBC. I'm not optimistic though. It's a bummer > that I ran into this at the END of all my changes... This is likely not an mxODBC problem, but related to the configuration of DTS and your database cluster. Here are some pointers: * "MSDTC Is Unavailable" Error When a Stand-Alone Instance of SQL Server Is in a Cluster Environment http://support.microsoft.com/kb/822473 * Transacted Commerce Server Pipeline Failure http://support.microsoft.com/kb/248403/ (see resolution steps 1 - 9) * Troubleshooting Guides for SQL Server http://www.microsoft.com/resources/documentation/sql/7/all/reskit/en-us/part7/sqc09.mspx http://www.microsoft.com/resources/documentation/sql/2000/all/reskit/en-us/part4/c1261.mspx -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 04 2004) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From joe at goldthwaites.com Thu Nov 4 21:53:37 2004 From: joe at goldthwaites.com (Joe Goldthwaite) Date: Thu Nov 4 21:53:47 2004 Subject: [DB-SIG] mxODBC.ProgrammingError: ('37000', 8501, "[Microsoft][ODBC SQL Server Driver][SQL Server]MSDTC on server 'xxxxx' is unavailable.", 4612) In-Reply-To: <4189E820.4010202@egenix.com> Message-ID: <002901c4c2b0$5c257d90$7264a8c0@jgoldamd> Hi Mark, I appreciate the reply. I went through the links you sent but was unable to find anything that would help. I don't think the problem is in the DTC configuration on the server because everything on the server end works. I can create views with linked tables and run the view from the SQL Query Analyzer and get the results. When I try to run the same view from mxODBC, I get the above error. If I use the win32 extensions to create an OleDB connection, I can run the query through that and it works fine. The only difference is the mxODBC connection. Here's a sample that illustrates; #Build my SQL statement with the linked table reference. I'm using OPENDATASOURCE instead of the linked table syntax #although both have the same problem sql = """ SELECT DISTINCT LTRIM(RTRIM(DRKY)) FROM OPENDATASOURCE( 'SQLOLEDB', 'Data Source=JDEENT;User ID=sa;Password=frayed' ).JDE_PRODUCTION.PRODCTL.F0005 WHERE RTRIM(LTRIM(DRSY)) = '00' AND RTRIM(LTRIM(DRRT)) = '07' AND RTRIM(LTRIM(DRKY)) <> '' """ #use WIN32 to create an ODBC object from win32com.client import DispatchEx OleDBConnection = DispatchEx("ADODB.Connection") OleDBConnection.Open('driver={SQL Server};server=JGOLDAMD;database=EISLocal') OleDBRecordset = DispatchEx("ADODB.Recordset") #Open the recordset and print the first row OleDBRecordset.Open(sql, OleDBConnection, 0) if not OleDBRecordset.EOF: for x in range(0, OleDBRecordset.Fields.Count): print OleDBRecordset.Fields(x).Value #Now we're going to use mxODBC to execute the same SQL statement from mx import ODBC ODBCConnection = ODBC.Windows.connect("EISLocal") #Create the connection csr = ODBCConnection.cursor() #Create the cursor object csr.execute(sql) #Excute the above SQL statement - this blows up. #It never gets here. allRecords = csr.fetchall() print allRecords It seems like if the problem was in the server configuration, it would not work with the SQL Analyzer or with the OLE DB object. The only difference is the connection. I'm not saying that the problem is in the ODBC stuff. In fact, it doesn't make any sense to me that linked tables would depend in any way on the type of connection used. It seems like the remote tables would be running at a much lower level. I can work around the problems by using the ODBC connection when I'm rebuilding my reporting database. I hate to do that because it ties me to using Windows as my host. I was planning to eventually convert the server to Linux. Let me know if you have any other ideas. Again, I thank you for taking the time to reply. I really do appreciate it. Joe Goldthwaite -----Original Message----- From: M.-A. Lemburg [mailto:mal@egenix.com] Sent: Thursday, November 04, 2004 1:28 AM To: joe@goldthwaites.com Cc: db-sig@python.org Subject: Re: [DB-SIG] mxODBC.ProgrammingError: ('37000', 8501, "[Microsoft][ODBC SQL Server Driver][SQL Server]MSDTC on server 'xxxxx' is unavailable.", 4612) Copying the error message here: [Microsoft][ODBC SQL Server Driver][SQL Server]MSDTC on server 'xxxxx' is unavailable.", 4612) Joe Goldthwaite wrote: > I suspect I'm not going to get a happy answer on this one. I ran into it > during the final testing of some major structural changes in my application. > I'm using SQL server as my database. I had originally built some data > tables for reporting and was storing them in the main database used by our > JDE application. Due to some additional requirements for other reporting > databases, I pulled the tables out and put them in their own database on a > separate server. I then used Microsoft SQL servers ability to link tables > to access the raw data from the JDE database and pull the data into the > reporting database. > > To do this, I specify the fully qualified table name in my stored procedure. > For example, to reference the F0901 table in the JDE_PRODUCTION database on > our JDEENT server, I have to reference it as > JDEENT.JDE_PRODUCTION.PRODDTA.F0901. JDEENT is the server name, > JDE_PRODUCTION is the database name and PRODDTA is the table owner. Note that there's a limit on the length of column names in SQL: mxODBC uses a 37 character limit which is what ANSI SQL defines. I don't that's a problem here, though, since you'd get a warning from the database in case of truncations. > If I execute the stored procedure or one of the individual queries from > within Microsoft's SQL Query Analyzer, it works fine. When I try to execute > the exact same SQL statement from the cursor.execute function, I get the > above MSDTC error. MSDTC stands for Microsoft Distributed Transaction > Coordinator. > > I suspect that the MS Query Analyzer is doing something different that > allows it to reference linked tables that the mxODBC code does not. I'm > hoping that someone knows about some setting or something that enables the > use of linked tables in mxODBC. I'm not optimistic though. It's a bummer > that I ran into this at the END of all my changes... This is likely not an mxODBC problem, but related to the configuration of DTS and your database cluster. Here are some pointers: * "MSDTC Is Unavailable" Error When a Stand-Alone Instance of SQL Server Is in a Cluster Environment http://support.microsoft.com/kb/822473 * Transacted Commerce Server Pipeline Failure http://support.microsoft.com/kb/248403/ (see resolution steps 1 - 9) * Troubleshooting Guides for SQL Server http://www.microsoft.com/resources/documentation/sql/7/all/reskit/en-us/par t7/sqc09.mspx http://www.microsoft.com/resources/documentation/sql/2000/all/reskit/en-us/ part4/c1261.mspx -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 04 2004) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From mal at egenix.com Thu Nov 4 22:11:31 2004 From: mal at egenix.com (M.-A. Lemburg) Date: Thu Nov 4 22:11:36 2004 Subject: [DB-SIG] mxODBC.ProgrammingError: ('37000', 8501, "[Microsoft][ODBC SQL Server Driver][SQL Server]MSDTC on server 'xxxxx' is unavailable.", 4612) In-Reply-To: <002901c4c2b0$5c257d90$7264a8c0@jgoldamd> References: <002901c4c2b0$5c257d90$7264a8c0@jgoldamd> Message-ID: <418A9B03.6060701@egenix.com> Joe Goldthwaite wrote: > Hi Mark, > > I appreciate the reply. I went through the links you sent but was unable to > find anything that would help. I don't think the problem is in the DTC > configuration on the server because everything on the server end works. I > can create views with linked tables and run the view from the SQL Query > Analyzer and get the results. When I try to run the same view from mxODBC, > I get the above error. If I use the win32 extensions to create an OleDB > connection, I can run the query through that and it works fine. The only > difference is the mxODBC connection. > > Here's a sample that illustrates; > > #Build my SQL statement with the linked table reference. I'm using > OPENDATASOURCE instead of the linked table syntax > #although both have the same problem > > sql = """ > SELECT DISTINCT LTRIM(RTRIM(DRKY)) > FROM > OPENDATASOURCE( > 'SQLOLEDB', > 'Data Source=JDEENT;User ID=sa;Password=frayed' > ).JDE_PRODUCTION.PRODCTL.F0005 > WHERE RTRIM(LTRIM(DRSY)) = '00' AND RTRIM(LTRIM(DRRT)) = '07' AND > RTRIM(LTRIM(DRKY)) <> '' > """ > > #use WIN32 to create an ODBC object > from win32com.client import DispatchEx > OleDBConnection = DispatchEx("ADODB.Connection") > OleDBConnection.Open('driver={SQL > Server};server=JGOLDAMD;database=EISLocal') > OleDBRecordset = DispatchEx("ADODB.Recordset") > > #Open the recordset and print the first row > OleDBRecordset.Open(sql, OleDBConnection, 0) > if not OleDBRecordset.EOF: > for x in range(0, OleDBRecordset.Fields.Count): > print OleDBRecordset.Fields(x).Value > > > #Now we're going to use mxODBC to execute the same SQL statement > from mx import ODBC > ODBCConnection = ODBC.Windows.connect("EISLocal") #Create the > connection > csr = ODBCConnection.cursor() #Create the cursor > object > csr.execute(sql) #Excute the above > SQL statement - this blows up. > #It never gets here. There may be a subtle difference between the ADO connection and the one you are using with mxODBC: in the ADO connection you are creating a per connection data source on the fly whereas with mxODBC you use the predefined data source from the ODBC manager. There may be permission problems or different setups involved due to this (the ODBC manager connection being setup statically in the ODBC manager rather than created on the fly). If the ADO connection works, you should be able to create a similar connection with mxODBC using the DriverConnect API: ODBCConnection = ODBC.Windows.DriverConnect( "driver={SQL Server};server=JGOLDAMD;database=EISLocal") # you may need to add: ";PWD=password;UID=userid" to the connection # string > allRecords = csr.fetchall() > print allRecords > > It seems like if the problem was in the server configuration, it would not > work with the SQL Analyzer or with the OLE DB object. The only difference > is the connection. I'm not saying that the problem is in the ODBC stuff. > In fact, it doesn't make any sense to me that linked tables would depend in > any way on the type of connection used. It seems like the remote tables > would be running at a much lower level. > > > I can work around the problems by using the ODBC connection when I'm > rebuilding my reporting database. I hate to do that because it ties me to > using Windows as my host. I was planning to eventually convert the server > to Linux. > > Let me know if you have any other ideas. Again, I thank you for taking the > time to reply. I really do appreciate it. It's always interesting to learn new things. Esp. with ODBC you can never learn enough (which helps in building good products ;-). > Joe Goldthwaite > > -----Original Message----- > From: M.-A. Lemburg [mailto:mal@egenix.com] > Sent: Thursday, November 04, 2004 1:28 AM > To: joe@goldthwaites.com > Cc: db-sig@python.org > Subject: Re: [DB-SIG] mxODBC.ProgrammingError: ('37000', 8501, > "[Microsoft][ODBC SQL Server Driver][SQL Server]MSDTC on server 'xxxxx' > is unavailable.", 4612) > > > Copying the error message here: > > [Microsoft][ODBC SQL Server Driver][SQL Server]MSDTC on server 'xxxxx' is > unavailable.", 4612) > > Joe Goldthwaite wrote: > >>I suspect I'm not going to get a happy answer on this one. I ran into it >>during the final testing of some major structural changes in my > > application. > >>I'm using SQL server as my database. I had originally built some data >>tables for reporting and was storing them in the main database used by our >>JDE application. Due to some additional requirements for other reporting >>databases, I pulled the tables out and put them in their own database on a >>separate server. I then used Microsoft SQL servers ability to link tables >>to access the raw data from the JDE database and pull the data into the >>reporting database. >> >>To do this, I specify the fully qualified table name in my stored > > procedure. > >>For example, to reference the F0901 table in the JDE_PRODUCTION database > > on > >>our JDEENT server, I have to reference it as >>JDEENT.JDE_PRODUCTION.PRODDTA.F0901. JDEENT is the server name, >>JDE_PRODUCTION is the database name and PRODDTA is the table owner. > > > Note that there's a limit on the length of column names in > SQL: mxODBC uses a 37 character limit which is what ANSI SQL > defines. I don't that's a problem here, though, since you'd get > a warning from the database in case of truncations. > > >>If I execute the stored procedure or one of the individual queries from >>within Microsoft's SQL Query Analyzer, it works fine. When I try to > > execute > >>the exact same SQL statement from the cursor.execute function, I get the >>above MSDTC error. MSDTC stands for Microsoft Distributed Transaction >>Coordinator. >> >>I suspect that the MS Query Analyzer is doing something different that >>allows it to reference linked tables that the mxODBC code does not. I'm >>hoping that someone knows about some setting or something that enables the >>use of linked tables in mxODBC. I'm not optimistic though. It's a bummer >>that I ran into this at the END of all my changes... > > > This is likely not an mxODBC problem, but related to the > configuration of DTS and your database cluster. Here are some > pointers: > > * "MSDTC Is Unavailable" Error When a Stand-Alone Instance of SQL Server > Is in a Cluster Environment > http://support.microsoft.com/kb/822473 > > * Transacted Commerce Server Pipeline Failure > http://support.microsoft.com/kb/248403/ > (see resolution steps 1 - 9) > > * Troubleshooting Guides for SQL Server > http://www.microsoft.com/resources/documentation/sql/7/all/reskit/en-us/par > t7/sqc09.mspx > http://www.microsoft.com/resources/documentation/sql/2000/all/reskit/en-us/ > part4/c1261.mspx > > -- > Marc-Andre Lemburg > eGenix.com > > Professional Python Services directly from the Source (#1, Nov 04 2004) > >>> Python/Zope Consulting and Support ... http://www.egenix.com/ > >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ > >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ > ________________________________________________________________________ > > ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 04 2004) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From joe at goldthwaites.com Thu Nov 4 23:14:45 2004 From: joe at goldthwaites.com (Joe Goldthwaite) Date: Thu Nov 4 23:14:55 2004 Subject: [DB-SIG] mxODBC.ProgrammingError: ('37000', 8501, "[Microsoft][ODBC SQL Server Driver][SQL Server]MSDTC on server 'xxxxx' is unavailable.", 4612) In-Reply-To: <418A9B03.6060701@egenix.com> Message-ID: <002d01c4c2bb$b1c42070$7264a8c0@jgoldamd> Hi Mark, It's nice to know how to create a connection without creating a DSN first. That will come in handy I'm sure. I made the change both with and without the SA password but it didn't fix the problem. I've been working with my SQL expert. He also thinks it has somthing to do with permissions. He's had me editing the registry and changing how the SQL service runs but so far, nothing has worked. I'm going to give up on it for now. I can use the OleDB connection on the section that has the problem and address it later if I switch to Linux. They want some additional enhancements finished next week and I'm out of time. (One guy's bonus depends on me finishing them - or so he says). Thanks again! Joe Goldthwaite -----Original Message----- From: M.-A. Lemburg [mailto:mal@egenix.com] Sent: Thursday, November 04, 2004 2:12 PM To: joe@goldthwaites.com Cc: db-sig@python.org Subject: Re: [DB-SIG] mxODBC.ProgrammingError: ('37000', 8501, "[Microsoft][ODBC SQL Server Driver][SQL Server]MSDTC on server 'xxxxx' is unavailable.", 4612) Joe Goldthwaite wrote: > Hi Mark, > > I appreciate the reply. I went through the links you sent but was unable to > find anything that would help. I don't think the problem is in the DTC > configuration on the server because everything on the server end works. I > can create views with linked tables and run the view from the SQL Query > Analyzer and get the results. When I try to run the same view from mxODBC, > I get the above error. If I use the win32 extensions to create an OleDB > connection, I can run the query through that and it works fine. The only > difference is the mxODBC connection. > > Here's a sample that illustrates; > > #Build my SQL statement with the linked table reference. I'm using > OPENDATASOURCE instead of the linked table syntax > #although both have the same problem > > sql = """ > SELECT DISTINCT LTRIM(RTRIM(DRKY)) > FROM > OPENDATASOURCE( > 'SQLOLEDB', > 'Data Source=JDEENT;User ID=sa;Password=frayed' > ).JDE_PRODUCTION.PRODCTL.F0005 > WHERE RTRIM(LTRIM(DRSY)) = '00' AND RTRIM(LTRIM(DRRT)) = '07' AND > RTRIM(LTRIM(DRKY)) <> '' > """ > > #use WIN32 to create an ODBC object > from win32com.client import DispatchEx > OleDBConnection = DispatchEx("ADODB.Connection") > OleDBConnection.Open('driver={SQL > Server};server=JGOLDAMD;database=EISLocal') > OleDBRecordset = DispatchEx("ADODB.Recordset") > > #Open the recordset and print the first row > OleDBRecordset.Open(sql, OleDBConnection, 0) > if not OleDBRecordset.EOF: > for x in range(0, OleDBRecordset.Fields.Count): > print OleDBRecordset.Fields(x).Value > > > #Now we're going to use mxODBC to execute the same SQL statement > from mx import ODBC > ODBCConnection = ODBC.Windows.connect("EISLocal") #Create the > connection > csr = ODBCConnection.cursor() #Create the cursor > object > csr.execute(sql) #Excute the above > SQL statement - this blows up. > #It never gets here. There may be a subtle difference between the ADO connection and the one you are using with mxODBC: in the ADO connection you are creating a per connection data source on the fly whereas with mxODBC you use the predefined data source from the ODBC manager. There may be permission problems or different setups involved due to this (the ODBC manager connection being setup statically in the ODBC manager rather than created on the fly). If the ADO connection works, you should be able to create a similar connection with mxODBC using the DriverConnect API: ODBCConnection = ODBC.Windows.DriverConnect( "driver={SQL Server};server=JGOLDAMD;database=EISLocal") # you may need to add: ";PWD=password;UID=userid" to the connection # string > allRecords = csr.fetchall() > print allRecords > > It seems like if the problem was in the server configuration, it would not > work with the SQL Analyzer or with the OLE DB object. The only difference > is the connection. I'm not saying that the problem is in the ODBC stuff. > In fact, it doesn't make any sense to me that linked tables would depend in > any way on the type of connection used. It seems like the remote tables > would be running at a much lower level. > > > I can work around the problems by using the ODBC connection when I'm > rebuilding my reporting database. I hate to do that because it ties me to > using Windows as my host. I was planning to eventually convert the server > to Linux. > > Let me know if you have any other ideas. Again, I thank you for taking the > time to reply. I really do appreciate it. It's always interesting to learn new things. Esp. with ODBC you can never learn enough (which helps in building good products ;-). > Joe Goldthwaite > > -----Original Message----- > From: M.-A. Lemburg [mailto:mal@egenix.com] > Sent: Thursday, November 04, 2004 1:28 AM > To: joe@goldthwaites.com > Cc: db-sig@python.org > Subject: Re: [DB-SIG] mxODBC.ProgrammingError: ('37000', 8501, > "[Microsoft][ODBC SQL Server Driver][SQL Server]MSDTC on server 'xxxxx' > is unavailable.", 4612) > > > Copying the error message here: > > [Microsoft][ODBC SQL Server Driver][SQL Server]MSDTC on server 'xxxxx' is > unavailable.", 4612) > > Joe Goldthwaite wrote: > >>I suspect I'm not going to get a happy answer on this one. I ran into it >>during the final testing of some major structural changes in my > > application. > >>I'm using SQL server as my database. I had originally built some data >>tables for reporting and was storing them in the main database used by our >>JDE application. Due to some additional requirements for other reporting >>databases, I pulled the tables out and put them in their own database on a >>separate server. I then used Microsoft SQL servers ability to link tables >>to access the raw data from the JDE database and pull the data into the >>reporting database. >> >>To do this, I specify the fully qualified table name in my stored > > procedure. > >>For example, to reference the F0901 table in the JDE_PRODUCTION database > > on > >>our JDEENT server, I have to reference it as >>JDEENT.JDE_PRODUCTION.PRODDTA.F0901. JDEENT is the server name, >>JDE_PRODUCTION is the database name and PRODDTA is the table owner. > > > Note that there's a limit on the length of column names in > SQL: mxODBC uses a 37 character limit which is what ANSI SQL > defines. I don't that's a problem here, though, since you'd get > a warning from the database in case of truncations. > > >>If I execute the stored procedure or one of the individual queries from >>within Microsoft's SQL Query Analyzer, it works fine. When I try to > > execute > >>the exact same SQL statement from the cursor.execute function, I get the >>above MSDTC error. MSDTC stands for Microsoft Distributed Transaction >>Coordinator. >> >>I suspect that the MS Query Analyzer is doing something different that >>allows it to reference linked tables that the mxODBC code does not. I'm >>hoping that someone knows about some setting or something that enables the >>use of linked tables in mxODBC. I'm not optimistic though. It's a bummer >>that I ran into this at the END of all my changes... > > > This is likely not an mxODBC problem, but related to the > configuration of DTS and your database cluster. Here are some > pointers: > > * "MSDTC Is Unavailable" Error When a Stand-Alone Instance of SQL Server > Is in a Cluster Environment > http://support.microsoft.com/kb/822473 > > * Transacted Commerce Server Pipeline Failure > http://support.microsoft.com/kb/248403/ > (see resolution steps 1 - 9) > > * Troubleshooting Guides for SQL Server > http://www.microsoft.com/resources/documentation/sql/7/all/reskit/en-us/par > t7/sqc09.mspx > http://www.microsoft.com/resources/documentation/sql/2000/all/reskit/en-us/ > part4/c1261.mspx > > -- > Marc-Andre Lemburg > eGenix.com > > Professional Python Services directly from the Source (#1, Nov 04 2004) > >>> Python/Zope Consulting and Support ... http://www.egenix.com/ > >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ > >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ > ________________________________________________________________________ > > ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 04 2004) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From brunson at brunson.com Fri Nov 19 20:02:29 2004 From: brunson at brunson.com (Eric Brunson) Date: Fri Nov 19 20:02:35 2004 Subject: [DB-SIG] Linux, ODBC and MSSQL Message-ID: <32430.63.171.103.6.1100890949.squirrel@www.comfortechassist.com> I've been tossed into a data conversion where it would be *extremely* convenient to connect to a MSSQL server running on Windows 2000 from my Linux workstation. I've researched to software available and I have freetds and the Sybase module based on it installed as well as mxODBC to try to use with ADODB, but I'm having trouble understanding how to address the database. I found a couple of references to using the NT name of the box as the host, but do I have so have some sort of WINS resolution enabled for that to work? If anyone can give some insight, I'd be very appreciative. Thanks, e. From mal at egenix.com Fri Nov 19 20:13:00 2004 From: mal at egenix.com (M.-A. Lemburg) Date: Fri Nov 19 20:13:03 2004 Subject: [DB-SIG] Linux, ODBC and MSSQL In-Reply-To: <32430.63.171.103.6.1100890949.squirrel@www.comfortechassist.com> References: <32430.63.171.103.6.1100890949.squirrel@www.comfortechassist.com> Message-ID: <419E45BC.2050309@egenix.com> Eric Brunson wrote: > I've been tossed into a data conversion where it would be *extremely* > convenient to connect to a MSSQL server running on Windows 2000 from my > Linux workstation. > > I've researched to software available and I have freetds and the Sybase > module based on it installed as well as mxODBC to try to use with ADODB, > but I'm having trouble understanding how to address the database. > > I found a couple of references to using the NT name of the box as the > host, but do I have so have some sort of WINS resolution enabled for that > to work? > > If anyone can give some insight, I'd be very appreciative. Try this route: Python -> mxODBC -> unixODBC -> FreeTDS ODBC driver -> MS SQL You should first install unixODBC, then the FreeTDS driver, check that it works using the unixODBC isql tool and then install mxODBC to talk to the unixODBC manager. Note: ADODB doesn't work on Linux, only on Windows. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Nov 19 2004) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From brunson at brunson.com Fri Nov 19 20:31:11 2004 From: brunson at brunson.com (Eric Brunson) Date: Fri Nov 19 20:31:17 2004 Subject: [DB-SIG] Linux, ODBC and MSSQL In-Reply-To: <419E45BC.2050309@egenix.com> References: <32430.63.171.103.6.1100890949.squirrel@www.comfortechassist.com> <419E45BC.2050309@egenix.com> Message-ID: <38010.63.171.103.6.1100892671.squirrel@www.comfortechassist.com> > Eric Brunson wrote: > > Try this route: > > > Python -> mxODBC -> unixODBC -> FreeTDS ODBC driver -> MS SQL > > > You should first install unixODBC, then the FreeTDS driver, > check that it works using the unixODBC isql tool and then install mxODBC to > talk to the unixODBC manager. I already have them all installed (wait, I have FreeTDS, I'll have to check that the ODBC driver is seperate or not). > Note: ADODB doesn't work on Linux, only on Windows. Oh, I was referring to the ADODB module for python from http://adodb.sourceforge.net It's a nice abstraction layer that work in both python and php if anyone's interested. From Casey at nerdworld.org Fri Nov 19 23:46:07 2004 From: Casey at nerdworld.org (Casey Bralla) Date: Fri Nov 19 23:46:18 2004 Subject: [DB-SIG] How can I retrieve single records in a specific order? Message-ID: <200411191746.07893.Casey@nerdworld.org> I'm writing a python application which will retrieve thousands of records from a MySQL database. I'm having trouble getting sequential records in the order I want, and was hoping someone could offer suggestions of how to proceed. Here is the python code I've gotten so far.... Database=MySQLdb.connect(db = Database, user = DatabaseUser, passwd = DatabasePassword, host = localhost) DatabaseCursor = Database.cursor() DatabaseCursor.execute("SELECT * FROM table1 ORDER BY field1") RecordData = DatabaseCursor.fetchone() You MySQL gurus can probably spot that I will receive a single record into "RecordData", and every time I run the routine, I will get the exact same record (in this case, the first record in the database table1 that is sorted by field1.) My Question: But how can I get a single record in this sort order, and then retrieve the next record in this same sort order? TIA! -- Casey Bralla Chief Nerd in Residence The NerdWorld Organisation From randall at tnr.cc Sat Nov 20 09:15:23 2004 From: randall at tnr.cc (Randall Smith) Date: Sat Nov 20 09:15:32 2004 Subject: [DB-SIG] pydal release Message-ID: <419EFD1B.4030501@tnr.cc> Some of you may remember a discussion a few months back about creating a database wrapper to hide differences between database modules. I made a release tonight that you can download from sourceforge. http://sourceforge.net/projects/pydal/ It is alpha so don't use it in production. Two of the key features are consistent, settable date types and paramstyles. I would appreciate bug reports and suggestions. Example: import dal dbdriver = dal.wrapdriver('psycopg') con = dbdriver # Set date type (optional - defaults to Python datetime) con.dtmod = 'py' # Set param style (optional - defaults to qmark) con.paramstyle = 'qmark' mydt = dbdriver.Date(2004,1,1) query = "Select * from mytable where dtcol > ?" cur = con.cursor() cur.execute(query, [mydt]) result = cur.fetchall() # Returned datetime fields will be Python datetime type # dtmod and paramstyle can be changed on the cursor. I appreciate all of your input thus far. Feel free to contact me directly or to post in the Sourceforge forums. Randall From peter at monicol.co.uk Sat Nov 20 11:36:44 2004 From: peter at monicol.co.uk (Peter Mott) Date: Sat Nov 20 11:37:46 2004 Subject: [DB-SIG] How can I retrieve single records in a specific order? In-Reply-To: <200411191746.07893.Casey@nerdworld.org> Message-ID: Hi Casey, You need to check out the Python DB-API specification at http://www.python.org/peps/pep-0249.html . Thge fetchone operation should return the next record and then None when there no more. Something like: RecordData = DatabaseCursor.fetchone() while RecordData != None: do something RecordData = DatabaseCursor.fetchone() HTH Peter > -----Original Message----- > From: db-sig-bounces@python.org [mailto:db-sig-bounces@python.org] On > Behalf Of Casey Bralla > Sent: 19 November 2004 22:46 > To: db-sig@python.org > Subject: [DB-SIG] How can I retrieve single records in a specific order? > > I'm writing a python application which will retrieve thousands of records > from > a MySQL database. I'm having trouble getting sequential records in the > order > I want, and was hoping someone could offer suggestions of how to proceed. > > Here is the python code I've gotten so far.... > > Database=MySQLdb.connect(db = Database, user = DatabaseUser, passwd = > DatabasePassword, host = localhost) > DatabaseCursor = Database.cursor() > DatabaseCursor.execute("SELECT * FROM table1 ORDER BY field1") > RecordData = DatabaseCursor.fetchone() > > > You MySQL gurus can probably spot that I will receive a single record into > "RecordData", and every time I run the routine, I will get the exact same > record (in this case, the first record in the database table1 that is > sorted > by field1.) > > My Question: But how can I get a single record in this sort order, and > then > retrieve the next record in this same sort order? > > > TIA! > -- > > Casey Bralla > Chief Nerd in Residence > The NerdWorld Organisation > _______________________________________________ > DB-SIG maillist - DB-SIG@python.org > http://mail.python.org/mailman/listinfo/db-sig From chris at cogdon.org Sat Nov 20 16:56:04 2004 From: chris at cogdon.org (Chris Cogdon) Date: Sat Nov 20 16:56:15 2004 Subject: [DB-SIG] How can I retrieve single records in a specific order? In-Reply-To: References: Message-ID: On Nov 20, 2004, at 02:36, Peter Mott wrote: > Hi Casey, > > You need to check out the Python DB-API specification at > http://www.python.org/peps/pep-0249.html . Thge fetchone operation > should > return the next record and then None when there no more. Something > like: > > RecordData = DatabaseCursor.fetchone() > while RecordData != None: > do something > RecordData = DatabaseCursor.fetchone() And... if you really need to ensure that they're done in separate SQL queries - for example, if you cannot hold onto the cursor between fetching each row - you can use MySQL's LIMIT or LIMIT/OFFSET syntax. .... LIMIT 5, 1 will return a result set with a single entry, but offset 5 positions into the otherwise full result set. The more-standard syntax of .... LIMIT 1 OFFSET 5 is supported by MySQL and other databases, such as PostgreSQL. ( LIMIT/OFFSET is supported by earlier versions of MySQL, but is far less standard than LIMIT/OFFSET) -- ("`-/")_.-'"``-._ Chris Cogdon . . `; -._ )-;-,_`) (v_,)' _ )`-.\ ``-' _.- _..-_/ / ((.' ((,.-' ((,/ fL From Casey at nerdworld.org Wed Nov 24 01:56:44 2004 From: Casey at nerdworld.org (Casey Bralla) Date: Wed Nov 24 01:57:08 2004 Subject: [DB-SIG] Multiple Fields in "Order by" Command Message-ID: <200411231956.44391.Casey@nerdworld.org> I'm trying to sort my database by multiple fields. I have written a query that says: "select * from TABLE1 order by FIELD1 + FIELD2 + FIELD3" Unfortunately, while I can sort by any single FIELD, I am unable to create the multi-field sort I want to create. I've tried parentheses, using the "&" sign, etc. I figure there's gotta be an easy way to do this... but I'll be darned if I can find it in the docs or on-line. Can somebody please point me in the right direction? BTW, This list is wonderful! Thanks to J Kennedy, Jim Tittlser, Randall Smith, Peter Mott, and Chris Cogdon for the help on the "fetchone()" and "fetchmany()" python statements. With your help, I was able to solve my problem, and I learned a bunch of stuff too. Thanks, guys! -- Casey Bralla Chief Nerd in Residence The NerdWorld Organisation From james at nonzerodigital.co.uk Wed Nov 24 02:06:54 2004 From: james at nonzerodigital.co.uk (James Gardner) Date: Wed Nov 24 02:06:50 2004 Subject: [DB-SIG] Multiple Fields in "Order by" Command In-Reply-To: <200411231956.44391.Casey@nerdworld.org> References: <200411231956.44391.Casey@nerdworld.org> Message-ID: <41A3DEAE.4030406@nonzerodigital.co.uk> Hi Casey, I beleive you wanted to use: SELECT * from TABLE1 order by FIELD1, FIELD2, FIELD3 using , rather than + There is a good SQL tutorial at: http://www.w3schools.com/sql/sql_orderby.asp Hope that helps, James -- http://www.pythonweb.org Casey Bralla wrote: > I'm trying to sort my database by multiple fields. I have written a query > that says: > "select * from TABLE1 order by FIELD1 + FIELD2 + FIELD3" > > Unfortunately, while I can sort by any single FIELD, I am unable to create the > multi-field sort I want to create. I've tried parentheses, using the "&" > sign, etc. I figure there's gotta be an easy way to do this... but I'll be > darned if I can find it in the docs or on-line. > > Can somebody please point me in the right direction? > > > > > BTW, This list is wonderful! Thanks to J Kennedy, Jim Tittlser, Randall > Smith, Peter Mott, and Chris Cogdon for the help on the "fetchone()" and > "fetchmany()" python statements. With your help, I was able to solve my > problem, and I learned a bunch of stuff too. Thanks, guys! From chris at cogdon.org Wed Nov 24 02:07:45 2004 From: chris at cogdon.org (Chris Cogdon) Date: Wed Nov 24 02:07:49 2004 Subject: [DB-SIG] Multiple Fields in "Order by" Command In-Reply-To: <200411231956.44391.Casey@nerdworld.org> References: <200411231956.44391.Casey@nerdworld.org> Message-ID: <3FC8F1B4-3DB5-11D9-A56B-000A95E3823E@cogdon.org> On Nov 23, 2004, at 16:56, Casey Bralla wrote: > I'm trying to sort my database by multiple fields. I have written a > query > that says: > "select * from TABLE1 order by FIELD1 + FIELD2 + FIELD3" > > Unfortunately, while I can sort by any single FIELD, I am unable to > create the > multi-field sort I want to create. I've tried parentheses, using the > "&" > sign, etc. I figure there's gotta be an easy way to do this... but > I'll be > darned if I can find it in the docs or on-line. > > Can somebody please point me in the right direction? orderbyfields [ 'field1`, 'field2', 'field3' ] "select * from table1 order by" + ",".join ( orderbyfields ) -- ("`-/")_.-'"``-._ Chris Cogdon . . `; -._ )-;-,_`) (v_,)' _ )`-.\ ``-' _.- _..-_/ / ((.' ((,.-' ((,/ fL From Casey at nerdworld.org Wed Nov 24 02:14:27 2004 From: Casey at nerdworld.org (Casey Bralla) Date: Wed Nov 24 02:14:48 2004 Subject: [DB-SIG] Multiple Fields in "Order by" Command In-Reply-To: <3FC8F1B4-3DB5-11D9-A56B-000A95E3823E@cogdon.org> References: <200411231956.44391.Casey@nerdworld.org> <3FC8F1B4-3DB5-11D9-A56B-000A95E3823E@cogdon.org> Message-ID: <200411232014.27374.Casey@nerdworld.org> I knew it would be simple, but I didn't think it would be **that** simple! Thanks guys! (And the help was in record time too!) On Tuesday 23 November 2004 8:07 pm, Chris Cogdon wrote: > On Nov 23, 2004, at 16:56, Casey Bralla wrote: > > I'm trying to sort my database by multiple fields. I have written a > > query > > that says: > > "select * from TABLE1 order by FIELD1 + FIELD2 + FIELD3" > > > > Unfortunately, while I can sort by any single FIELD, I am unable to > > create the > > multi-field sort I want to create. I've tried parentheses, using the > > "&" > > sign, etc. I figure there's gotta be an easy way to do this... but > > I'll be > > darned if I can find it in the docs or on-line. > > > > Can somebody please point me in the right direction? > > orderbyfields [ 'field1`, 'field2', 'field3' ] > "select * from table1 order by" + ",".join ( orderbyfields ) -- Casey Bralla Chief Nerd in Residence The NerdWorld Organisation From james at pythonweb.org Thu Nov 25 02:58:19 2004 From: james at pythonweb.org (James Gardner) Date: Thu Nov 25 02:58:13 2004 Subject: [DB-SIG] Announcing SnakeSQL Message-ID: <41A53C3B.6000009@pythonweb.org> Hi All, Just thought some of you may be interested in this pure Python database I've written over the last couple of weeks. The download URL is http://www.pythonweb.org/projects/snakesql/ SnakeSQL is a pure Python SQL database written to remove the dependence of the Python Web Modules on 3rd party C-based database drivers but designed to be a useful database in its own right. The database supports the simplest possible subset of ANSI SQL 92 including NULLs (something other pure Python databases such as Gadfly do not currently support as far as I know). The database is fully DB-API 2.0 compliant and is written in layers so that it could be extended to support different storage mechanisms. Currently implemented are a fast binary DBM driver (default) and a slower CSV file driver (handy for viewing table contents when designing and developing an application or database structure). This is an alpha release designed to give interested users the chance to feedback bug reports or comments. The database appears stable on Windows XP Python 2.2 and 2.3 and successfully runs the test script and test SQL in Interactive Prompt mode. It has not been tested more extensively. If you use the database and it doesn't work, please let me know. Documentation is at http://www.pythonweb.org/projects/snakesql/doc/0.3.4/ All the best, James -- http://www.pythonweb.org/ From jmutter at uakron.edu Tue Nov 30 21:27:45 2004 From: jmutter at uakron.edu (Jay Mutter) Date: Thu Dec 2 04:21:52 2004 Subject: [DB-SIG] SnakeSQL Message-ID: <4B444CC0-430E-11D9-A663-000D93537766@uakron.edu> Good afternoon: I am wondering if anyone knows if SnakeSQL can use foreign keys? I have looked at the documentation but have found nothing regarding this. Thanks Jay mutter