Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/Runtime/XSharp.VFP.Tests/CommandTests.prg
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,34 @@ BEGIN NAMESPACE XSharp.VFP.Tests
END TRY
RETURN

[Fact];
METHOD TestCreateTableWithPath() AS VOID
VAR cOldDir := Directory.GetCurrentDirectory()
VAR cTempPath := Path.Combine(Path.GetTempPath(), "CreateTableTest_" + Guid.NewGuid():ToString("N"))
VAR cSubDir := Path.Combine(cTempPath, "SubDir")
System.IO.Directory.CreateDirectory(cSubDir)

TRY
SET DEFAULT TO (cTempPath)
VAR cFile1 := Path.Combine(cSubDir, "TestTable1.dbf")
CREATE TABLE (cFile1) (Id INT, Name C(20))
Assert.True(File.Exists(cFile1))
Assert.True(Used("TestTable1"))

VAR cFile2 := Path.Combine(cSubDir, "TestTable2.dbf")
CREATE TABLE (cFile2) (Id INT, Value c(10))
Assert.True(File.Exists(cFile2))
Assert.True(Used("TestTable2"))
XSharp.CoreDb.CloseAll()
FINALLY
System.IO.Directory.SetCurrentDirectory(cOldDir)
TRY
System.IO.Directory.Delete(cTempPath, TRUE)
CATCH
END TRY
END TRY
END METHOD

END CLASS

END NAMESPACE
16 changes: 10 additions & 6 deletions src/Runtime/XSharp.VFP/SQL/EmbeddedSql.prg
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,20 @@ STATIC CLASS FoxEmbeddedSQL
var aField := {col:Name, ((Char)col:FieldType):ToString(), col:Length, col:Decimals, col:Name, col:Flags}
AAdd(aStruct, aField)
next

VAR cTable := oTable:Name
VAR cAlias := Path.GetFileNameWithoutExtension(oTable:Name)
if oTable:IsCursor
cTable := System.IO.Path.GetTempFileName()
cTable := Path.GetTempFileName()
cAlias := oTable:Name
ENDIF
if RuntimeState.Workareas.FindAlias(oTable:Name) != 0
DbCloseArea(oTable:Name)
if RuntimeState.Workareas.FindAlias(cAlias) != 0
DbCloseArea(cAlias)
endif
DbCreate(cTable, aStruct, "DBFVFP", TRUE, oTable:Name)
DbCloseArea(oTable:Name)
DbUseArea(TRUE, "DBFVFP", cTable, oTable:Name, FALSE, FALSE)
DbCreate(cTable, aStruct, "DBFVFP", TRUE, cAlias)
DbCloseArea(cAlias)
DbUseArea(TRUE, "DBFVFP", cTable, cAlias, FALSE, FALSE)

FOR var nI := 1 to oTable:Columns:Count
var oCol := oTable:Columns[nI-1]
DbFieldInfo(DBS_CAPTION, nI, oCol:Caption)
Expand Down
Loading