1

I have a InMemory that gets created, what I then want to do is run INSERT, UPDATE and DELETE queries on the table. The code i have at the moment is below, I create a new InMemory table, add it to the map (which works).

    Dim pInMemTable As ITable
    'create Temp DP table
    Set pWSF = New InMemoryWorkspaceFactory
    Dim PName As esriSystem.IName
    Set PName = pWSF.Create("fred", "InMemory", Nothing, 0)
    ' Debug.Print ">>" + PName.NameString + "<<"
    Set pFWS = PName.Open

    Dim pFlds As IFieldsEdit
    Set pFlds = New esriGeoDatabase.Fields
    pFlds.AddField MakeField("OBJECTID", esriFieldTypeOID)
    pFlds.AddField MakeField("DP_REF", esriFieldTypeString, 10)
    pFlds.AddField MakeField("WANTED", esriFieldTypeString, 1)

    Dim pUID As New UID
    pUID.Value = "esriGeodatabase.Object"

    Dim ptable As ITable
    Set ptable = pFWS.CreateTable("DP_Temp", pFlds, pUID, Nothing, "")
   ' Debug.Print ptable.

    Dim pSAT As IStandaloneTable
    Set pSAT = New StandaloneTable
    Set pSAT.Table = ptable
    pSAT.Name = "DP_Temp999"

    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument

    Dim pSATC As IStandaloneTableCollection
    Set pSATC = pMxDoc.FocusMap

    pSATC.AddStandaloneTable pSAT
    pMxDoc.UpdateContents

    Set pInMemTable = pSAT

    Dim path As String
    path = "InMemory/DP_Temp999"
    If pWSF Is Nothing Then
        MsgBox "pwsf is nothing"
    Else
       ' MsgBox "pwsf is something"
        'MsgBox pWSF.WorkspaceDescription(False)

        'pwsf.Open(
        Set pWS = pWSF.OpenFromFile(path, 0) ' **********PWS doesnt get set***********
        If pWS Is Nothing Then
            MsgBox "PWS IS NOTHING" 
        Else
            MsgBox ("Yes!!")
        End If

    End If

but the code fails where PWS is getting set as it always returns as Nothing. I have tried various ways of setting the path value e.g. "InMemory/DP_Temp999", "In_Memory/DP_Temp" and trying the "\" as opposed to "/" but it still comes back as nothing. Does anyone have any ideas please? or is there a better way of executing SQL on a table that will allow SELECT, DELETE and INSERTS.

****UPDATE** Right I have been working on this for a few days have have been able to set pWS, by casting by ptable to a idataset object and then setting pWS to the pdataset propertyset properties which works. However I have then tried the following code, to see if SQL can be executed

    If pWS Is Nothing Then
        MsgBox "PWS IS NOTHING"
    Else
        'MsgBox ("Yes!!")
        Dim pWorkspaceProperties As IWorkspaceProperties
        Set pWorkspaceProperties = pWS

        Dim pWSProperty As IWorkspaceProperty
        Set pWSProperty = pWorkspaceProperties.Property(esriWorkspacePropertyGroup, esriWorkspacePropCanExecuteSQL)
        If pWSProperty.IsSupported = True Then
            MsgBox "SQL is supported"
            Dim sql As String
            'sql = "select * from 'DP_TEMP';"
            sql = "UPDATE dp_temp set dp_temp.[DP_REF] = 'Test';"
            pWS.ExecuteSQL sql
        Else
            MsgBox "SQL is not supported"
        End If
    End If

When the code is run, the pWSProperty.IsSupported returns as True, however when the .ExecuteSQL method is run, I get the following error Runtime Error 445 - Object doesn't support this action. So I am a bit confused as to whether SQL can be run or not.

  • What are the other variables (pFWS and pWS)? – kenbuja Jun 26 '13 at 13:08
  • pFWS is IFeatureWorkSpace, and pWS is IWorkspace. They were global variables, but makes no difference if I put it within the procedure. – MapMan Jun 26 '13 at 13:15
  • 1
    Can you try this using a ScratchWorkspace instead of an InMemoryWorkspace? The InMemory workspaces do have some limitations. – kenbuja Jul 2 '13 at 14:18
1

This code gets the IWorkspace (I added the declarations for the pFWS and pWS into the code to make it work in my example)

        Dim pInMemTable As ESRI.ArcGIS.Geodatabase.ITable
        'create Temp DP table
        Dim pWSF As ESRI.ArcGIS.Geodatabase.IWorkspaceFactory = New ESRI.ArcGIS.DataSourcesGDB.InMemoryWorkspaceFactory
        Dim PName As ESRI.ArcGIS.esriSystem.IName
        PName = pWSF.Create("fred", "InMemory", Nothing, 0)
        ' Debug.Print ">>" + PName.NameString + "<<"
        Dim pFWS As ESRI.ArcGIS.Geodatabase.IFeatureWorkspace = PName.Open
        Dim pWS As ESRI.ArcGIS.Geodatabase.IWorkspace

        ' the rest of your code 

        If pWSF Is Nothing Then
            MsgBox("pwsf is nothing")
        Else
            ' MsgBox "pwsf is something"
            'MsgBox pWSF.WorkspaceDescription(False)

            'pwsf.Open(
            'pWS = pWSF.OpenFromFile(path, 0) ' **********PWS doesnt get set***********
            pWS = pFWS
            If pWS Is Nothing Then
                MsgBox("PWS IS NOTHING")
            Else
                MsgBox("Yes!!")
            End If

        End If
  • Ken, Looking at your code you have set pWS to the Featureworkspace (pFWS) , which i have got to work, however doesn't it need to be set to the pWSF (workspace factory), so that I can open the inmemory table and then run the executesql method? – MapMan Jun 26 '13 at 16:11
  • Canty seem to edit my comment above...Here is a link which shows what i want to do (example is a FGDB table) forums.esri.com/Thread.asp?c=93&f=992&t=230422 – MapMan Jun 26 '13 at 16:17
  • You're correct on that. Is the workspace you're really after the DP_Temp table instead of the DP_Temp999 table? – kenbuja Jun 26 '13 at 18:18
  • The table name is called DP_Temp,The alias name of the table when it is added to the TOC is DP_Temp999, I just left it as I was trying to figure if changing the name made any difference. So yes the workspace I am after is the DP_Temp table. – MapMan Jun 26 '13 at 21:07
  • Original question updated – MapMan Jul 2 '13 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.