Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HOW TO ADD NEW COLUMN #107

Open
ctw28 opened this issue Aug 22, 2021 · 4 comments
Open

HOW TO ADD NEW COLUMN #107

ctw28 opened this issue Aug 22, 2021 · 4 comments
Milestone

Comments

@ctw28
Copy link

ctw28 commented Aug 22, 2021

i need to add some column field in same file. can u tell how? cause in README.md i only found add column when create new file. thank you

@gam6itko
Copy link
Collaborator

@ctw28 unfortunately there is currently no way to add a new column to an existing file. If you really need it, I can start developing this feature.

@ctw28
Copy link
Author

ctw28 commented Aug 23, 2021

yes, i need it, and i would say thank you if you want to develop this feature. and i think, it will be great feature.

@gam6itko gam6itko added this to the v3 milestone Mar 10, 2022
@JohnnyQ352
Copy link

JohnnyQ352 commented Aug 26, 2024

You can add a column to an existing table in Laravel before you set data

use Illuminate\Support\Facades\DB;
DB::raw('ALTER TABLE '.$FullTableLocationPath.' ADD COLUMN new_column_name VARCHAR(255)');

$dbfTable = new WritableTable($FullTableLocationPath, [
'editMode' => WritableTable::EDIT_MODE_CLONE,
]);

foreach ($query as $row) {
$record = $dbfTable->appendRecord();

foreach ($row as $field => $value) {
	$column = strtolower($field);
	$record->set($column, $value);
}
$dbfTable->writeRecord()->save();

}

$dbfTable->close();
}

You can do it using PDO in laravel as well

$dsn = 'dbase://your_path/to/your_dbase_file';
$pdo = new PDO($dsn);

$sql = 'ALTER TABLE your_table_name ADD COLUMN new_column_name VARCHAR(255)';
$pdo->exec($sql);

.... Then do set data parts here..

@JohnnyQ352
Copy link

JohnnyQ352 commented Aug 27, 2024

Adding notes about adding columns. The 2.2.0 version now has a way to add columns to a new table.
You can read all the columns in an existing structure and then create a new table with the extra columns.
This will allow you to create a table with the added columns, then just fill the new table with the old table's
data and while you do, add the data to the new column.

Note: This is good if the table is not too big. I have tables I would not do this with because they are huge, like in the millions of records from old DBASE software. But if they are not so big, then pump the jam man. Good Luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants