• 0

Make a cell unchangeable?


Question

22 answers to this question

Recommended Posts

  • 0

In the MySQL client I use, you make the cell a 'primary key' or 'key' to prevent the data being changed. I'm assuming it would be the same throughout all MySQL clients.

A primary key (and keys/indexes in general) do a very different thing to what you're suggesting... I don't know if you're doing it on purpose, but the advice you're giving out on these forums is really bad...

  • 0

Hi guys,

Simple question really - is it possible to make a cell unchangeable, or otherwise to lock it? Only 1 cell needed, but if row/table locking is possible, this is also an opktion.

Thanks! :)

You didn't say what in, but I think assuming some common dbms is safe. Most dbms's should allow users to be created and allow you to grant/revoke table/column level access to data. MySQL allows this. If you need to restrict access to specific records in a table, then this should be possible through the use of views.

  • 0

A primary key (and keys/indexes in general) do a very different thing to what you're suggesting... I don't know if you're doing it on purpose, but the advice you're giving out on these forums is really bad...

You asked how to make a cells data unchangeable, here's some information I picked up about keys from a google search

  • Always has a value (can not be null)
  • Has a value which remains the same (does not change)
  • Has a unique value for each record in the table

You asked a question, I replied with an answer, and other sources also back the information I told you.

I now know who not to offer my help to in the future, goodbye :)

  • 0

You asked how to make a cells data unchangeable, here's some information I picked up about keys from a google search

  • Always has a value (can not be null)
  • Has a value which remains the same (does not change)
  • Has a unique value for each record in the table

You asked a question, I replied with an answer, and other sources also back the information I told you.

I now know who not to offer my help to in the future, goodbye :)

-Alex- is actually entirely correct about the solution you proposed, keys/indexes have nothing to do with access restrictions or making data attributes read-only like you suggested.

  • 0

-Alex- is actually entirely correct about the solution you proposed, keys/indexes have nothing to do with access restrictions or making data attributes read-only like you suggested.

From the question he proposed, I thought he would have a cell that would hold a piece of data that will never be edited, hence the suggestion of a key.

I didn't think he wanted to protect a cell so that the data couldn't be edited; apologies.

  • 0

From the question he proposed, I thought he would have a cell that would hold a piece of data that will never be edited, hence the suggestion of a key.

I didn't think he wanted to protect a cell so that the data couldn't be edited; apologies.

even so, that is in no way what keys/indexes are for

  • 0

even so, that is in no way what keys/indexes are for

I'm guessing the rules for keys in Microsoft Access and MySQL are different then? If not, I think the education is flawed; if I've forgot this basic piece of information, I'm not sure how the hell I achieved an A* in 'Database software (creation and management)'.

My understanding of keys is, what I quoted in my last post, and that they are a pieces of information used to identify rows in a table. Going of this belief, and my use of keys I am perfectly correct. I always use keys in terms of user IDs, usernames, passwords etc. pieces of unique data that will never change.

  • 0

I'm guessing the rules for keys in Microsoft Access and MySQL are different then? If not, I think the education is flawed; if I've forgot this basic piece of information, I'm not sure how the hell I achieved an A* in 'Database software (creation and management)'.

My understanding of keys is, what I quoted in my last post, and that they are a pieces of information used to identify rows in a table. Going of this belief, and my use of keys I am perfectly correct. I always use keys in terms of user IDs, usernames, passwords etc. pieces of unique data that will never change.

You are correct in thinking that a primary key is used to uniquely identify a row/record, however there is nothing to stop them changing, the only requirement is that they remain unique within the set of records in that table. Also, you can only have one primary key per table.

  • 0

You are correct in thinking that a primary key is used to uniquely identify a row/record, however there is nothing to stop them changing, the only requirement is that they remain unique within the set of records in that table. Also, you can only have one primary key per table.

Ah, well my client doesn't let me edit cells which are assigned a primary key value, hence why I said it in my first post.

  • 0

Matteh, you're completely correct about primary keys being a unique ID assigned to a row (in combination with autoincrement)... but yes, I'm looking to protect a cell/column/table. Sorry for the way I wrote my post... I've been working on an overdue project from 5pm yesterday til 2pm today and I hadn't had any sleep.

You didn't say what in, but I think assuming some common dbms is safe. Most dbms's should allow users to be created and allow you to grant/revoke table/column level access to data. MySQL allows this. If you need to restrict access to specific records in a table, then this should be possible through the use of views.

The dbms was in the tag :p But yes, I should've mentioned it somewhere in the thread too. I'm running MySQL 5.5.19. As for column level locking, can you tell me a bit more about this?

What might complicate this more is that I want the access restriction to stand when the database is dumped and re-imported on to a different server... and I get the feeling that ain't possible.

  • 0

The dbms was in the tag :p But yes, I should've mentioned it somewhere in the thread too. I'm running MySQL 5.5.19. As for column level locking, can you tell me a bit more about this?

What might complicate this more is that I want the access restriction to stand when the database is dumped and re-imported on to a different server... and I get the feeling that ain't possible.

tags aren't shown on my mobile browser :p

you just need to check out the grant syntax: http://dev.mysql.com/doc/refman/5.5/en/grant.html

you can absolutely copy the privileges over, they're written in sql.

  • 0

Hi guys,

Simple question really - is it possible to make a cell unchangeable, or otherwise to lock it? Only 1 cell needed, but if row/table locking is possible, this is also an option.

Thanks! :)

Only way I can think of doing it would involve a trigger, which means MySQL 5.0 minimum. I assume you want it so it can't be changed with an UPDATE?

Here's an example. Change column_name, database_name to the applicable values and be sure to run the the entire SQL in one transaction.

DELIMITER $$

DROP TRIGGER column_name_readonly$$

CREATE TRIGGER column_name_readonly BEFORE UPDATE ON table_name
FOR EACH ROW BEGIN
SET NEW.column_name = OLD.column_name;
END;
$$

DELIMITER;[/CODE]

  • 0

Only way I can think of doing it would involve a trigger, which means MySQL 5.0 minimum. I assume you want it so it can't be changed with an UPDATE?

Here's an example. Change column_name, database_name to the applicable values and be sure to run the the entire SQL in one transaction.

<snip>

This worked perfectly! Thank you very much! :D

  • 0

Just out of time to edit, but in the end I used:

CREATE TRIGGER `copyright_readonly` BEFORE UPDATE ON `options`
FOR EACH ROW BEGIN
SET NEW.copyright = OLD.copyright;
END

CREATE TRIGGER `no_delete` BEFORE DELETE ON `options`
FOR EACH ROW BEGIN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'You cannot delete from this table!';
END

CREATE TRIGGER `no_insert` BEFORE INSERT ON `options`
FOR EACH ROW BEGIN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'You cannot insert into this table!';
END

Just one more question... I presume a user could delete these triggers? What (if anything) would stop them from being able to do so?

  • 0

whether or not the dbms user has the 'trigger' privilege

What might complicate this more is that I want the access restriction to stand when the database is dumped and re-imported on to a different server... and I get the feeling that ain't possible.

  • 0

I won't be able to modify privs on the other server. It's to go to a client in the form of a load of .php files and .sql file... my client will have to setup the MySQL user herself. So obviously that user's gonna have all privs.

Guess I can't prevent it?

  • 0

I won't be able to modify privs on the other server. It's to go to a client in the form of a load of .php files and .sql file... my client will have to setup the MySQL user herself. So obviously that user's gonna have all privs.

Guess I can't prevent it?

create a php file to hold "config" data, have them stick the username in that; give them a php "setup" script that will take the username in the config file and issue the necessary create user and grant sql commands to set it up, which they can run after importing the sql file to create the actual database. if necessary, work out a suitable username for them beforehand, and ensure the existing user the setup will be run under has the necessary grant privileges itself. i don't know what you're doing about the existing user credential that was to be used, but you could perhaps have a login form displayed by the setup script that would take those credentials and use them to connect to the database with admin privileges to then create the users for your application (as specified in the config file).
This topic is now closed to further replies.
  • Posts

    • While I agree with all that, it just proves there's an a** built for every seat.
    • Lol are you mad because I'm not using AI? I'd rather pay people than lose a bunch of potential customers and get humilated because I used AI. A lot of people won't purchase a game if it used AI during development.
    • LibreWolf 152.0-1 by Razvan Serea LibreWolf is an independent “fork” of Firefox, with the primary goals of privacy security and user freedom. It is the community run successor to LibreFox. LibreWolf is designed to increase protection against tracking and fingerprinting techniques, while also including a few security improvements. This is achieved through our privacy and security oriented settings and patches. LibreWolf also aims to remove all the telemetry, data collection and annoyances, as well as disabling anti-freedom features like DRM. LibreWolf features: Latest Firefox — LibreWolf is compiled directly from the latest build of Firefox Stable. You will have the the latest features, and security updates. Independent Build — LibreWolf uses a build independent of Firefox and has its own settings, profile folder and installation path. As a result, it can be installed alongside Firefox or any other browser. No phoning home — Embedded server links and other calling home functions are removed. In other words, minimal background connections by default. User settings updates Extensions firewall: limit internet access for extensions. Multi-platform (Windows/Linux/Mac/and soon Android) Community-Driven Dark theme (classic and advanced) LibreWolf privacy features: Delete cookies and website data on close. Include only privacy respecting search engines like DuckDuckGo and Searx. Include uBlockOrigin with custom default filter lists, and Tracking Protection in strict mode, to block trackers and ads. Strip tracking elements from URLs, both natively and through uBO. Enable dFPI, also known as Total Cookie Protection. Enable RFP which is part of the Tor Uplift project. RFP is considered the best in class anti-fingerprinting solution, and its goal is to make users look the same and cover as many metrics as possible, in an effort to block fingerprinting techniques. Always display user language as en-US to websites, in order to protect the language used in the browser and in the OS. Disable WebGL, as it is a strong fingerprinting vector. Prevent access to the location services of the OS, and use Mozilla's location API instead of Google's API. Limit ICE candidates generation to a single interface when sharing video or audio during a videoconference. Force DNS and WebRTC inside the proxy, when one is being used. Trim cross-origin referrers, so that they don't include the full URI. Disable link prefetching and speculative connections. Disable disk cache and clear temporary files on close. Disable form autofill. Disable search and form history...and more. LibreWolf 152.0-1 changelog: Upstream release, see the Firefox 152.0 Release Notes Notable changes: The AppImages are now built on Codeberg along with the other releases We have decided to wait a bit longer to enable the settings redesign, due to use being aware of multiple upstream issues Download: LibreWolf 64-bit | Portable 64-bit | ~100.0 MB (Open Source) Download: ARM64 | Portable ARM64 Links: LibreWolf Home Page | Addons | Screenshot | Reddit Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • hahahahah wow hahahah you sure got me there hahahahahah, you know that bad performance is always due to poor optimization by the developers, right???
    • "I know for a fact I'll never own one of these." This is why choice is better than government regulation. Globaly Android has something like 72% of the smartphone market. Granted the vast majority of that is low end phones. Apple can and should charge whatever they want. The market will decide if it is too much.
  • Recent Achievements

    • Week One Done
      Huge Trailer earned a badge
      Week One Done
    • Week One Done
      Classifyskilleducation earned a badge
      Week One Done
    • One Month Later
      eurospharma62 earned a badge
      One Month Later
    • Week One Done
      With What earned a badge
      Week One Done
    • Week One Done
      Harris Gilbert earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      560
    2. 2
      +Edouard
      168
    3. 3
      PsYcHoKiLLa
      72
    4. 4
      Michael Scrip
      64
    5. 5
      ATLien_0
      64
  • Tell a friend

    Love Neowin? Tell a friend!