Архив метки: fetchone

Python pyodbc postgres

import pyodbc
conn_str = (
    "DRIVER={PostgreSQL Unicode};"
    "DATABASE=postgres;"
    "UID=postgres;"
    "PWD=whatever;"
    "SERVER=localhost;"
    "PORT=5432;"
    )
conn = pyodbc.connect(conn_str)
crsr = conn.execute("SELECT 123 AS n")
row = crsr.fetchone()
print(row)
crsr.close()
conn.close()

MSSQL Пример цикла по результатам запроса

DECLARE @mesto  varchar(30);  
DECLARE c CURSOR FOR SELECT mesto from MyPlaces
OPEN c
FETCH NEXT FROM c INTO @mesto
WHILE @@FETCH_STATUS = 0
BEGIN
      select 'Здесь ' + @mesto
      FETCH NEXT FROM c INTO @mesto
END
CLOSE c
DEALLOCATE c