2013-08-22 252 views
8

非常に単純なpostgresqlデータベースへのアップデートで、動作しません。 sql select文は問題なく、正しい値を返します。「データベース間参照は実装されていません」と表示されるのはなぜですか?

それは私が更新を取得する場合、それはエラーをスローします:

{"ERROR [0A000] ERROR: cross-database references are not implemented: "openerp.public.product_template"; Error while executing the query"}. 

私はvb.netとPostgreSQL 9.2を使用しています。

私がしたいのは、名前フィールドを説明の内容と一致するように変更することだけです。

log: 
LOG 0 duration: 34.000 ms statement: SELECT * FROM product_template where import_date = '08/22/2013' 
LOG 0 duration: 11.000 ms statement: select n.nspname, c.relname, a.attname, a.atttypid, t.typname, a.attnum, a.attlen, a.atttypmod, a.attnotnull, c.relhasrules, c.relkind, c.oid, d.adsrc from (((pg_catalog.pg_class c inner join pg_catalog.pg_namespace n on n.oid = c.relnamespace and c.oid = 20496) inner join pg_catalog.pg_attribute a on (not a.attisdropped) and a.attnum > 0 and a.attrelid = c.oid) inner join pg_catalog.pg_type t on t.oid = a.atttypid) left outer join pg_attrdef d on a.atthasdef and d.adrelid = a.attrelid and d.adnum = a.attnum order by n.nspname, c.relname, attnum 
LOG 0 duration: 12.000 ms parse _PLAN000000001D2CFB60: SELECT * FROM product_template where import_date = '08/22/2013' 
LOG 0 duration: 11.000 ms statement: select ta.attname, ia.attnum, ic.relname, n.nspname, tc.relname from pg_catalog.pg_attribute ta, pg_catalog.pg_attribute ia, pg_catalog.pg_class tc, pg_catalog.pg_index i, pg_catalog.pg_namespace n, pg_catalog.pg_class ic where tc.oid = 20496 AND tc.oid = i.indrelid AND n.oid = tc.relnamespace AND i.indisprimary = 't' AND ia.attrelid = i.indexrelid AND ta.attrelid = i.indrelid AND ta.attnum = i.indkey[ia.attnum-1] AND (NOT ta.attisdropped) AND (NOT ia.attisdropped) AND ic.oid = i.indexrelid order by ia.attnum 
LOG 0 duration: 0.000 ms statement: select current_schema() 
LOG 0 duration: 1.000 ms statement: select c.relhasrules, c.relkind, c.relhasoids from pg_catalog.pg_namespace u, pg_catalog.pg_class c where u.oid = c.relnamespace and c.relname = 'product_template' and u.nspname = 'public' 
LOG 0 duration: 1.000 ms statement: select c.relhasrules, c.relkind, c.relhasoids from pg_catalog.pg_namespace u, pg_catalog.pg_class c where u.oid = c.relnamespace and c.relname = 'product_template' and u.nspname = 'public' 
ERROR 0A000 cross-database references are not implemented: "openerp.public.product_template" 

コード:実際にDBに送らなっていますかを見るためにあなたのPostgreSQLのログでエラーの

Private Sub btnChgNameToDescr_Click(sender As Object, e As EventArgs) Handles btnChgNameToDescr.Click 

    Dim objConn As New System.Data.Odbc.OdbcConnection 
    Dim objCmd As New System.Data.Odbc.OdbcCommand 
    Dim dtAdapter As New System.Data.Odbc.OdbcDataAdapter 
    Dim ds As New DataSet 

    Me.Cursor = System.Windows.Forms.Cursors.WaitCursor 

    Dim strConnString As String 
    Dim strSQL As String 
    Dim iRecCount As Integer 

    Me.Cursor = System.Windows.Forms.Cursors.WaitCursor 

    If objConn.State = ConnectionState.Open Then 
     'do nothing 
    Else 
     strConnString = "Dsn=PostgreSQL35W;database=OpenERP;server=localhost;port=5432;uid=openpg;pwd=openpgpwd" 
     objConn.ConnectionString = strConnString 
     objConn.Open() 
    End If 


    If Me.txtImportDate.Text = "" Then 
     MsgBox("Import Date field cannot be blank.") 
     Exit Sub 
    End If 

    Dim str_import_date As String = Me.txtImportDate.Text 


    strSQL = "SELECT * FROM product_template where import_date = " & "'" & str_import_date & "'" 

    dtAdapter.SelectCommand = objCmd 

    With objCmd 
     .Connection = objConn 
     .CommandText = strSQL 
     .CommandType = CommandType.Text 
     .ExecuteNonQuery() 

     dtAdapter.Fill(ds, "product_template") 

     iRecCount = ds.Tables("product_template").Rows.Count 

    End With 

    If iRecCount = 0 Then 
     MsgBox("No records found.") 
     Me.Cursor = System.Windows.Forms.Cursors.Default 
     Exit Sub 
    End If 


    Dim cb As New Odbc.OdbcCommandBuilder(dtAdapter) 


    'change the name field to item_description 
    With ds 
     For i As Integer = 0 To .Tables("product_template").Rows.Count - 1 

      'this works, returns a string 
      Dim str_default_code As String = (.Tables(0).Rows(i).Item("name").ToString) 
      'this works 
      Dim str_item_description As String = (.Tables(0).Rows(i).Item("description").ToString) 

      .Tables("product_template").Rows(i).Item("name") = str_item_description 
      'setting the variable doesn't work either - Dim str_item_description As String = "BH LITE BRT" 

      'this throws the error 
      dtAdapter.Update(ds, "product_template") 

     Next 
    End With 

    Me.Cursor = System.Windows.Forms.Cursors.Default 
End Sub 
+0

これは問題であるかどうかわかりませんが、コードの途中にあるExecuteNonQuery()はSELECTクエリには必要ありません – Steve

+1

通常は複数のドットを含む引用符で囲まれていない識別子で、db .schema.table'が例外をトリガします。私はすぐに原因を見つける* DBサーバーのログファイル*実際の違反ステートメントが既定のログ設定でエラーメッセージと共に記載されています。 –

+0

@ErwinBrandstetterは 'str_import_date = 22.08.2013'のようです。文字列の連結は常にあなたを蹴る方法を見つけるでしょう – Steve

答えて

1

ルック。私はあなたのコードを修正する方法がわかりません。なぜなら、私はそのプラットフォームをよく知らないからです。また、現在のアプローチではSQLインジェクションの問題が発生するため、パラメータ化されたクエリに移行する必要があります。

ただし、エラーは余分な名前空間があることを意味します。コンテキストに応じて、通常の名前空間はschema.table.columnまたはschema.tableです。テーブルをschema.table.columnと指定しようとすると、database.schema.tableと表示され、このエラーが発生します。同様に余分なドットがある場合は、誤ってdatabase.schema.table.columnと指定することもできます(これによりエラーが発生します)。

これは、文字列化されたSQLが実際には悪い考えですが、実際に問題の表面を傷つけるわけではありません。

関連する問題